up
All checks were successful
Deploy to Production / deploy (push) Successful in 8s

This commit is contained in:
lubukhu
2026-01-24 13:32:25 +07:00
parent 8a255877cb
commit 6c3e93636e
5 changed files with 79 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ var tdv_sdk = {
missingIndices: [], // lưu index các slot bị thiếu
blankIndexes: [], // danh sách index bị trống
missingWords: [],
lastAnswerResult: null, // { correct: true/false, raw: data }
blankCount: 1, // số ô trống (server control)
@@ -377,6 +378,7 @@ var tdv_sdk = {
// ==================== TRACKING TỪ THEO VỊ TRÍ SLOT ====================
placedWords: [], // Mảng lưu từ theo vị trí slot [0, 1, 2, 3, ...]
userSequence: [], // sequence cuối cùng gửi cho SDK iframe
canSubmit: 0, // 0 = chưa đủ từ, 1 = đủ từ có thể submit
// Reset mảng placedWords khi bắt đầu câu hỏi mới
@@ -386,6 +388,41 @@ var tdv_sdk = {
this.canSubmit = 0;
console.log("🔄 Reset placedWords:", this.placedWords);
},
buildUserSequence: function () {
var result = [];
for (var i = 0; i < this.correctWords.length; i++) {
// blank slot → lấy user đặt
if (this.isBlankIndex(i)) {
result.push(this.placedWords[i] || "");
}
// preset slot → lấy từ đúng
else {
result.push(this.correctWords[i]);
}
}
this.userSequence = result;
console.log("📦 User sequence built:", result);
return result;
},
submitSequenceAnswer: function () {
if (this.canSubmit !== 1) {
console.warn("❌ Cannot submit sequence incomplete");
return;
}
var sequence = this.buildUserSequence();
window.parent.postMessage({
type: "SDK_CHECK_ANSWER",
game_id: this.gameID,
question_id: this.currentQuestion.id,
choice: sequence
}, "*");
console.log("📤 Sent sequence to SDK iframe:", sequence);
},
// Alias cho tương thích
resetPlacedLetters: function () {
@@ -415,7 +452,7 @@ var tdv_sdk = {
}
return 0;
},
// Alias cho tương thích với SQ Word
setLetterAtSlot: function (word, slotIndex) {
return this.setWordAtSlot(word, slotIndex);
@@ -454,6 +491,42 @@ var tdv_sdk = {
}
}
},
handleAnswerResult: function (data) {
// data ví dụ:
// {
// type: "SDK_ANSWER_RESULT",
// question_id,
// correct: true/false,
// score_delta,
// extra
// }
this.lastAnswerResult = {
correct: !!data.correct,
raw: data
};
console.log(
data.correct ? "✅ Answer correct (SDK)" : "❌ Answer wrong (SDK)",
data
);
// Bắn trigger cho game (chưa xử lý ở C2 bước này)
if (window['TDVTriger']) {
window['TDVTriger'].runtime.trigger(
cr.plugins_.TDVplugin.prototype.cnds.OnAnswerChecked,
window['TDVTriger']
);
}
},
isLastAnswerCorrect: function () {
return this.lastAnswerResult ? (this.lastAnswerResult.correct ? 1 : 0) : -1;
},
getLastAnswerRaw: function () {
return this.lastAnswerResult ? this.lastAnswerResult.raw : null;
},
getMissingCount: function () {
return this.missingWords.length;
},
@@ -1118,4 +1191,5 @@ window.addEventListener("message", function (event) {
if (!event.data) return;
if (event.data.type === "SERVER_PUSH_DATA") tdv_sdk.load(event.data.jsonData);
if (event.data.type === "SERVER_PUSH_LEADERBOARD") tdv_sdk.loadLeaderboard(event.data.leaderboardData);
if (event.data.type === "SDK_ANSWER_RESULT") { tdv_sdk.handleAnswerResult(event.data); }
});