diff --git a/G102-sequence/tdv_sdk.js b/G102-sequence/tdv_sdk.js index b06eb53..3de99ba 100644 --- a/G102-sequence/tdv_sdk.js +++ b/G102-sequence/tdv_sdk.js @@ -265,7 +265,40 @@ var tdv_sdk = { if (!q.parts && q.sentence) { q.parts = q.sentence.split(/\s+/); } + // ===== LOGIC GỐC (BẮT BUỘC PHẢI CÓ) ===== + this.correctSentence = String(q.sentence || "").trim(); + + if (q.parts && Array.isArray(q.parts) && q.parts.length > 0) { + this.currentWords = [...q.parts]; + this.correctWords = this.correctSentence.split(/\s+/).filter(w => w.length > 0); + console.log("📦 Using server-provided parts:", this.currentWords); + } else { + this.correctWords = this.correctSentence.split(/\s+/).filter(w => w.length > 0); + this.currentWords = this.shuffleArray([...this.correctWords]); + console.log("🔀 Auto-split and shuffled words"); + } + + // reset + blank logic + this.resetPlacedWords(); + this.generateBlankIndexes(); + this.generateMissingWords(); + + this.newWidth = this.calculateWordWidth(this.currentWords); + this.listPosX = this.getObjectPositions( + this.currentWords.length, + this.newWidth, + this.margin, + this.maxWWidth + ); + + this.lastLoadedLevel = this.level; + + console.log("📝 Correct sentence:", this.correctSentence); + console.log("📝 Display words:", this.currentWords); + console.log("📝 Word count:", this.currentWords.length); + } + }, // Tính width dựa trên số từ và độ dài từ dài nhất