This commit is contained in:
lubukhu
2026-01-22 14:16:00 +07:00
parent 5b18b68315
commit 2568d138ca
5 changed files with 147 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "SQ_SENTENCE", "name": "G102-sequence",
"short_name": "SQ_SENTENCE", "short_name": "G102-sequence",
"start_url": "index.html", "start_url": "index.html",
"display": "fullscreen", "display": "fullscreen",
"orientation": "any", "orientation": "any",

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>SQ_SENTENCE</title> <title>G102-sequence</title>
<!-- Standardised web app manifest --> <!-- Standardised web app manifest -->
<link rel="manifest" href="appmanifest.json" /> <link rel="manifest" href="appmanifest.json" />

View File

@@ -1,5 +1,5 @@
{ {
"version": 1769054861, "version": 1769066087,
"fileList": [ "fileList": [
"data.js", "data.js",
"c2runtime.js", "c2runtime.js",

View File

@@ -26,7 +26,7 @@ var tdv_sdk = {
correctWords: [], // Mảng các từ đúng (theo thứ tự) correctWords: [], // Mảng các từ đúng (theo thứ tự)
listPosX: [], listPosX: [],
newWidth: 150, newWidth: 150,
maxWWidth: 1400, maxWWidth: 1200,
margin: 40, margin: 40,
// --- DỮ LIỆU MẶC ĐỊNH (FALLBACK) --- // --- DỮ LIỆU MẶC ĐỊNH (FALLBACK) ---
@@ -103,8 +103,8 @@ var tdv_sdk = {
// --- CÁC HÀM CALLBACK --- // --- CÁC HÀM CALLBACK ---
onGameStart: function () { console.log("SDK: Sentence Game Started"); }, onGameStart: function () { console.log("SDK: Sentence Game Started"); },
onAnswerChecked: function (isCorrect, data) { console.log("SDK: Answer Checked", isCorrect); }, onAnswerChecked: function (isCorrect, data) { console.log("SDK: Answer Checked", isCorrect); },
onGameFinished: function (finalData) { console.log("SDK: Game Finished", finalData); }, onGameFinished: function (finalData) { console.log("SDK: Game Finished", finalData,data); },
onLeaderboardLoaded: function (data) { console.log("SDK: Leaderboard Loaded"); }, onLeaderboardLoaded: function (data) { console.log("SDK: Leaderboard Loaded",data); },
// --- KHỞI TẠO & LOAD DỮ LIỆU --- // --- KHỞI TẠO & LOAD DỮ LIỆU ---
init: function () { init: function () {
@@ -810,51 +810,159 @@ var tdv_sdk = {
}, },
// ==================== VỊ TRÍ CĂN GIỮA VỚI SPACING CỐ ĐỊNH ==================== // ==================== VỊ TRÍ CĂN GIỮA VỚI SPACING CỐ ĐỊNH ====================
// centerX: tâm màn hình (mặc định 960) // ===== LAYOUT CONFIG =====
// spacing: khoảng cách giữa các ô (CỐ ĐỊNH, mặc định 200) startY: 840,
// ===== CẤU HÌNH CHỈNH TRONG CODE ===== spacingX: 210,
centerX: 600, // Tâm màn hình X
startY: 840, // Y của dòng đầu tiên
spacingX: 210, // Khoảng cách giữa các ô (X & Y)
spacingY: 95, spacingY: 95,
maxPerRow: 5, // Số ô mỗi dòng
// Lấy vị trí X của ô theo index (căn giữa + spacing cố định)
// Sử dụng: Browser.ExecJS("tdv_sdk.getCenteredPosX(" & loopindex & ", 960, 200)")
getCenteredPosX: function (index) {
// ===== HELPER: chia số ô theo số dòng =====
getRowConfig: function () {
var n = this.currentWords.length; var n = this.currentWords.length;
if (n <= 0) return this.centerX;
var row = Math.floor(index / this.maxPerRow); // 1 dòng
if (n <= 5) {
return [n];
}
// Số ô trong dòng hiện tại // 2 dòng (dòng trên nặng hơn)
var itemsInRow = Math.min( if (n <= 10) {
this.maxPerRow, var top = Math.ceil(n * 0.6);
n - row * this.maxPerRow var bottom = n - top;
); return [top, bottom];
}
// 3 dòng (giảm dần)
var rows = [];
var remain = n;
// dòng 1 ~ 40%
var r1 = Math.ceil(n * 0.4);
rows.push(r1);
remain -= r1;
// dòng 2 ~ 35% của phần còn lại
var r2 = Math.ceil(remain * 0.5);
rows.push(r2);
remain -= r2;
// dòng 3: còn lại
rows.push(remain);
return rows;
},
// ===== X POSITION =====
getCenteredPosX: function (index) {
var rows = this.getRowConfig();
var centerX = this.maxWWidth / 2;
var acc = 0;
var row = 0;
var col = 0;
for (var i = 0; i < rows.length; i++) {
if (index < acc + rows[i]) {
row = i;
col = index - acc;
break;
}
acc += rows[i];
}
var itemsInRow = rows[row];
var totalWidth = (itemsInRow - 1) * this.spacingX; var totalWidth = (itemsInRow - 1) * this.spacingX;
var startX = this.centerX - totalWidth / 2; var startX = centerX - totalWidth / 2;
var col = index % this.maxPerRow;
return startX + col * this.spacingX; return startX + col * this.spacingX;
}, },
// ===== TÍNH Y (XUỐNG DÒNG) ===== // ===== Y POSITION =====
getCenteredPosY: function () { getCenteredPosY: function (index) {
var rows = this.getRowConfig();
var acc = 0;
var row = 0;
for (var i = 0; i < rows.length; i++) {
if (index < acc + rows[i]) {
row = i;
break;
}
acc += rows[i];
}
return this.startY + row * this.spacingY;
},
// ===== CHECKER Y (luôn dưới answers) =====
getCheckerBaseY: function (index) {
var rows = this.getRowConfig();
// Tổng chiều cao answers
var answerBlockHeight = rows.length * this.spacingY;
// Xác định checker đang ở dòng nào
var acc = 0;
var row = 0;
for (var i = 0; i < rows.length; i++) {
if (index < acc + rows[i]) {
row = i;
break;
}
acc += rows[i];
}
// Checker nằm dưới answers + theo dòng tương ứng
return this.startY
+ this.spacingY // khoảng cách giữa answers & checker
+ row * this.spacingY // dòng checker
+ 10; // padding nhỏ
},
// centerX: 600, // Tâm màn hình X
// startY: 800, // Y của dòng đầu tiên
// spacingX: 210, // Khoảng cách giữa các ô (X & Y)
// spacingY: 95,
// maxPerRow: 5, // Số ô mỗi dòng
// // Lấy vị trí X của ô theo index (căn giữa + spacing cố định)
// // Sử dụng: Browser.ExecJS("tdv_sdk.getCenteredPosX(" & loopindex & ", 960, 200)")
// getCenteredPosX: function (index) {
// var n = this.currentWords.length;
// if (n <= 0) return this.centerX;
// var row = Math.floor(index / this.maxPerRow); // var row = Math.floor(index / this.maxPerRow);
return this.startY;
},
getCheckerBaseY: function (index) {
var n = this.currentWords.length; // // Số ô trong dòng hiện tại
if (n <= 0) return this.startY; // var itemsInRow = Math.min(
// this.maxPerRow,
// n - row * this.maxPerRow
// );
var row = Math.floor(index / this.maxPerRow); // var totalWidth = (itemsInRow - 1) * this.spacingX;
// checker nằm dưới dòng answers cuối // var startX = this.centerX - totalWidth / 2;
return this.startY + 1 * this.spacingY + row * this.spacingY + 10;
}, // var col = index % this.maxPerRow;
// return startX + col * this.spacingX;
// },
// // ===== TÍNH Y (XUỐNG DÒNG) =====
// getCenteredPosY: function () {
// // var row = Math.floor(index / this.maxPerRow);
// return this.startY;
// },
// getCheckerBaseY: function (index) {
// var n = this.currentWords.length;
// if (n <= 0) return this.startY;
// var row = Math.floor(index / this.maxPerRow);
// // checker nằm dưới dòng answers cuối
// return this.startY + 1 * this.spacingY + row * this.spacingY + 10;
// },
shuffleArray: function (array) { shuffleArray: function (array) {
for (let i = array.length - 1; i > 0; i--) { for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)); const j = Math.floor(Math.random() * (i + 1));