This commit is contained in:
@@ -137,5 +137,99 @@
|
||||
</script>
|
||||
<script src="./sdk/package/dist/sena-game-sdk.js"></script>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* ==============================
|
||||
* SDK BRIDGE – G120 (SEQUENCE)
|
||||
* ==============================
|
||||
* - Chỉ làm cầu nối
|
||||
* - Không xử lý game logic
|
||||
* - Không chấm điểm
|
||||
*/
|
||||
|
||||
window.SDK_BRIDGE = {
|
||||
sdk: null,
|
||||
gameData: [],
|
||||
currentIndex: 0,
|
||||
gameCode: "G120",
|
||||
mode: "preview"
|
||||
};
|
||||
|
||||
// ===== INIT SDK =====
|
||||
function initSDKBridge() {
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
SDK_BRIDGE.mode = urlParams.get("mode") || "preview";
|
||||
|
||||
SDK_BRIDGE.sdk = new SenaGameSDK({
|
||||
iframePath: "./sdk/package/dist/sdk-iframe/index.html",
|
||||
gameCode: SDK_BRIDGE.gameCode,
|
||||
mode: SDK_BRIDGE.mode,
|
||||
debug: true,
|
||||
|
||||
onReady: function (sdk) {
|
||||
console.log("✅ [SDK BRIDGE] SDK Ready");
|
||||
},
|
||||
|
||||
onDataReady: function (data) {
|
||||
console.log("📥 [SDK BRIDGE] Data Ready:", data);
|
||||
|
||||
SDK_BRIDGE.gameData = data.items || [];
|
||||
SDK_BRIDGE.currentIndex = 0;
|
||||
|
||||
// Đẩy data cho Construct 2
|
||||
if (window.tdv_sdk) {
|
||||
window.tdv_sdk.gameData = SDK_BRIDGE.gameData;
|
||||
window.tdv_sdk.currentQuestionIndex = 0;
|
||||
window.tdv_sdk.loadQuestions();
|
||||
}
|
||||
|
||||
if (window.c2_callFunction) {
|
||||
window.c2_callFunction("OnSDKDataReady", []);
|
||||
}
|
||||
},
|
||||
|
||||
onAnswerResult: function (result) {
|
||||
console.log("📝 [SDK BRIDGE] Answer Result:", result);
|
||||
window.answerResult = result.correct ? 1 : 0;
|
||||
|
||||
if (window.TDVTriger) {
|
||||
window.TDVTriger.runtime.trigger(
|
||||
cr.plugins_.TDVplugin.prototype.cnds.OnAnswerChecked,
|
||||
window.TDVTriger
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
onGameComplete: function (result) {
|
||||
console.log("🏁 [SDK BRIDGE] Game Complete:", result);
|
||||
},
|
||||
|
||||
onError: function (err) {
|
||||
console.error("❌ [SDK BRIDGE] SDK Error:", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ===== HELPERS CHO CONSTRUCT 2 =====
|
||||
function submitSequenceAnswer(sequenceArray) {
|
||||
if (!SDK_BRIDGE.sdk) return;
|
||||
SDK_BRIDGE.sdk.submitAnswer({
|
||||
selectedAnswer: sequenceArray
|
||||
});
|
||||
}
|
||||
|
||||
function nextQuestion() {
|
||||
SDK_BRIDGE.currentIndex++;
|
||||
if (window.tdv_sdk) {
|
||||
window.tdv_sdk.currentQuestionIndex = SDK_BRIDGE.currentIndex;
|
||||
window.tdv_sdk.loadQuestions();
|
||||
}
|
||||
}
|
||||
|
||||
// Auto init
|
||||
window.addEventListener("load", initSDKBridge);
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user