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

This commit is contained in:
lubukhu
2026-01-24 14:25:23 +07:00
parent 259a24bff3
commit c5e587f1e5

View File

@@ -254,76 +254,13 @@ var tdv_sdk = {
lastLoadedLevel: -1, lastLoadedLevel: -1,
loadQuestions: function () { loadQuestions: function () {
if (this.lastLoadedLevel === this.level && this.currentWords.length > 0) {
console.log("⏭️ Sentence", this.level + 1, "already loaded, skipping...");
return;
}
this.currentQuestion = this.list[this.level]; this.currentQuestion = this.list[this.level];
this.questionStartTime = new Date();
window.gameState = 0;
window.answerResult = -1;
if (this.currentQuestion) { if (this.currentQuestion) {
// ===== NORMALIZE DATA FROM SDK IFRAME ===== if (!this.currentQuestion.id) this.currentQuestion.id = "Q" + (this.level + 1);
if (this.currentQuestion.content && !this.currentQuestion.sentence) { console.log(`📝 Loaded Q${this.level + 1}: ${this.currentQuestion.question}`);
this.currentQuestion.sentence = this.currentQuestion.content;
}
if (Array.isArray(this.currentQuestion.options) && !this.currentQuestion.parts) {
this.currentQuestion.parts = this.currentQuestion.options;
}
// Fallback cuối: nếu vẫn chưa có parts
if (!this.currentQuestion.parts && this.currentQuestion.sentence) {
this.currentQuestion.parts = this.currentQuestion.sentence.split(/\s+/);
}
// Lấy câu đúng từ field "sentence"
this.correctSentence = String(this.currentQuestion.sentence || "").trim();
// PHƯƠNG THỨC 1: Nhận parts đã chia sẵn từ server
if (this.currentQuestion.parts && Array.isArray(this.currentQuestion.parts) && this.currentQuestion.parts.length > 0) {
// Server đã gửi sẵn parts (có thể đã shuffle hoặc chưa)
this.currentWords = [...this.currentQuestion.parts];
// Tách correctWords từ sentence để so sánh
this.correctWords = this.correctSentence.split(/\s+/).filter(w => w.length > 0);
console.log("📦 Using server-provided parts:", this.currentWords);
}
// PHƯƠNG THỨC 2: Tự tách câu và shuffle (fallback)
else {
// TÁCH CÂU THÀNH CÁC TỪ (by space)
this.correctWords = this.correctSentence.split(/\s+/).filter(w => w.length > 0);
// Shuffle các từ
this.currentWords = this.shuffleArray([...this.correctWords]);
console.log("🔀 Auto-split and shuffled words");
}
// ===== FILL BLANK MODE =====
this.missingIndices = [];
if (this.gameMode === "fill_blank") {
var total = this.correctWords.length;
// random 1 slot bị thiếu
var missing = Math.floor(Math.random() * total);
this.missingIndices.push(missing);
console.log("🕳️ Missing slot index:", missing);
}
// Tính width dựa trên số từ và độ dài từ
this.newWidth = this.calculateWordWidth(this.currentWords);
// Tính vị trí X cho từng từ
this.listPosX = this.getObjectPositions(this.currentWords.length, this.newWidth, this.margin, this.maxWWidth);
// Đánh dấu đã load level này
this.lastLoadedLevel = this.level;
console.log("📝 Correct sentence:", this.correctSentence);
console.log("📝 Display words:", this.currentWords);
console.log("📝 Word count:", this.currentWords.length);
this.generateBlankIndexes();
this.generateMissingWords();
} }
}, },