soyoo-cocos/cocos-embed/SoyooFacade.ts

50 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// v1.0 2024/12/01
// Soyoo facade to handle assets network transfroming.
export enum SoyooLifecyle {
Ready = 100, // 游戏初始化完成
Start = 200, // 游戏正式开始
Pause = 300, // 游戏暂停
Resume = 400, // 游戏从暂停恢复
Complete = 500, // 游戏结束, 全部完成
}
interface ISoyooFacadeImpl {
onLifecyleReport(lifecycle: SoyooLifecyle): void
onGameInstall(): void
}
// Only support web now.
let soyooFacadeImpl: ISoyooFacadeImpl;
(function() {
const window = globalThis;
const global = globalThis;
const self = globalThis;
(function() {
if ((window as any)?.$soyooFacadeImpl) {
soyooFacadeImpl = (window as any)?.$soyooFacadeImpl
console.log("SoyooFacade inited")
} else {
console.warn("soyooFacadeImpl not provided")
}
}).call(this);
}).call(this);
// 渠道转换的中间协议
export class SoyooFacade {
// 在游戏相应的生命周期时调用该方法。其中Ready/Start/Complete必须调用
static ReportLifeCycle(lifecycle: SoyooLifecyle) {
console.log("[SoyooFacade] ReportLifeCycle: " + lifecycle)
soyooFacadeImpl?.onLifecyleReport?.(lifecycle)
}
// 当用户点击并需要跳转到商店下载页面时,调用该方法。
static InstallGame() {
console.log("[SoyooFacade] InstallGame")
soyooFacadeImpl?.onGameInstall?.()
}
}