This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
var tdv_sdk = {
|
||||
// --- KHO DỮ LIỆU NỘI BỘ ---
|
||||
mode: 'live',
|
||||
game_code: 'G120',
|
||||
list: [],
|
||||
currentQuestion: null,
|
||||
level: 0,
|
||||
@@ -110,67 +108,33 @@ var tdv_sdk = {
|
||||
onLeaderboardLoaded: function (data) { console.log("SDK: Leaderboard Loaded",data); },
|
||||
|
||||
// --- KHỞI TẠO & LOAD DỮ LIỆU ---
|
||||
init: function (config) {
|
||||
init: function () {
|
||||
var self = this;
|
||||
config = config || {};
|
||||
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
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 urlParams = new URLSearchParams(window.location.search);
|
||||
const bgParam = urlParams.get('bg');
|
||||
if (bgParam) {
|
||||
this.themeSettings.current_bg = bgParam.startsWith('bg') ? bgParam : "bg" + bgParam;
|
||||
}
|
||||
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
|
||||
window.answerResult = -1;
|
||||
window.gameState = 0; // 0: idle | 1: waiting | 2: answered
|
||||
|
||||
console.log("TDV SDK INIT:", this.mode, this.game_code);
|
||||
|
||||
if (typeof SenaGameSDK === "undefined") {
|
||||
console.error("SenaGameSDK not found → fallback preview");
|
||||
this._loadDataToGame(this.defaultData);
|
||||
return;
|
||||
if (urlParams.has('offline') || urlParams.has('demo')) {
|
||||
console.log("🔧 SDK: Offline/Demo mode - Loading default data");
|
||||
this.loadDefaultData();
|
||||
} else {
|
||||
setTimeout(function () {
|
||||
if (!self.serverDataLoaded && self.list.length === 0) {
|
||||
console.warn("⚠️ SDK: No server data after 3s - Loading default data");
|
||||
self.loadDefaultData();
|
||||
}
|
||||
|
||||
/* ===== 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);
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
loadDefaultData: function () {
|
||||
|
||||
Reference in New Issue
Block a user