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

This commit is contained in:
lubukhu
2026-01-24 13:49:18 +07:00
parent 63e5f66222
commit 24be1df458

View File

@@ -1,7 +1,5 @@
var tdv_sdk = { var tdv_sdk = {
// --- KHO DỮ LIỆU NỘI BỘ --- // --- KHO DỮ LIỆU NỘI BỘ ---
mode: 'live',
game_code: 'G120',
list: [], list: [],
currentQuestion: null, currentQuestion: null,
level: 0, level: 0,
@@ -110,67 +108,33 @@ var tdv_sdk = {
onLeaderboardLoaded: function (data) { console.log("SDK: Leaderboard Loaded",data); }, 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 (config) { init: function () {
var self = this; var self = this;
config = config || {}; const urlParams = new URLSearchParams(window.location.search);
const bgParam = urlParams.get('bg');
var urlParams = new URLSearchParams(window.location.search); if (bgParam) {
this.themeSettings.current_bg = bgParam.startsWith('bg') ? bgParam : "bg" + bgParam;
this.mode = config.mode || urlParams.get("mode") || "live";
this.game_code = config.game_code || urlParams.get("game_code") || "G120";
// Standalone → Preview
if (window.self === window.parent && this.mode === "live") {
console.warn("Standalone detected → PREVIEW mode");
this.mode = "preview";
} }
const id = urlParams.get('game_id') || this.gameID;
console.log("🔌 SDK: Sentence Game Initialized. Waiting for data...");
window.parent.postMessage({
type: "GAME_READY",
game_id: id,
available_bgs: this.themeSettings.bg_list,
selected_bg: this.themeSettings.current_bg
}, "*");
// Globals for Construct 2 polling if (urlParams.has('offline') || urlParams.has('demo')) {
window.answerResult = -1; console.log("🔧 SDK: Offline/Demo mode - Loading default data");
window.gameState = 0; // 0: idle | 1: waiting | 2: answered this.loadDefaultData();
} else {
console.log("TDV SDK INIT:", this.mode, this.game_code); setTimeout(function () {
if (!self.serverDataLoaded && self.list.length === 0) {
if (typeof SenaGameSDK === "undefined") { console.warn("⚠️ SDK: No server data after 3s - Loading default data");
console.error("SenaGameSDK not found → fallback preview"); self.loadDefaultData();
this._loadDataToGame(this.defaultData);
return;
} }
}, 3000);
/* ===== INIT SDK ===== */
this.sdk = new SenaGameSDK({
iframePath: "./dist/sdk-iframe/index.html",
mode: this.mode,
gameCode: this.game_code,
debug: true,
onReady: function (sdk) {
sdk.pushData({
items: self.defaultData.items
});
},
onDataReady: function (data) {
self._loadDataToGame(data);
},
onAnswerResult: function (result) {
self._handleAnswerResult(result);
},
onGameComplete: function (result) {
self._handleGameComplete(result);
},
onSessionStart: function (session) {
self.gameID = session.gameId;
self.userId = session.userId;
},
onError: function (err) {
console.error("SDK ERROR:", err);
} }
});
}, },
loadDefaultData: function () { loadDefaultData: function () {