import { director, find, game } from "cc"; import { DataSystem } from "../core/data/DataSystem"; import { Http, HttpResponseCode } from "../core/net/Http"; import { HttpSystem } from "../core/net/HttpSystem"; import { WindowSystem } from "../core/ui/window/WindowSystem"; import { FightData } from "../fight/FightData"; import { TaskData } from "../task/TaskData"; import { HttpErrorCode } from "./HttpErrorCode"; import { ADData } from "./jsb/ADData"; import { DeviceData } from "./jsb/DeviceData"; import { ISJSB, platform } from "./jsb/platform"; import { WechatData } from "./jsb/WechatData"; /** * 全局数据接口 * @description 真正意义的ECS架构不应该存在这个,这里有是因为网赚项目JSB工程对接的历史遗留问题 * @deprecated 已废弃,请使用DataSystem.getData */ export class g { /** * @deprecated 已废弃,请使用DataSystem.getData */ public static get deviceData(): DeviceData { return DataSystem.getData(DeviceData); } /** * @deprecated 已废弃,请使用DataSystem.getData */ public static get adData(): ADData { return DataSystem.getData(ADData); } /** * @deprecated 已废弃,请使用DataSystem.getData */ public static get wechatData(): WechatData { return DataSystem.getData(WechatData); } /** * 激励视频加载失败 */ public static onRewardVideoADError() { g.adData.ad_type = 5; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); this.callback(null); this.callback = null; } /** * 激励视频展⽰ */ public static onRewardVideoADShow() { g.adData.ad_type = 4; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); } /** * 放弃视频奖励 */ public static onRewardVideoADLoss() { this.callback(null); this.callback = null; } private static callback: (value: ADData) => void; /** * 显示激励视频 * @returns */ public static showRewardVideo() { return new Promise((resolve => { if (!ISJSB()) {//web版本直接返回成功 resolve(DataSystem.getData(ADData)); return; } //3秒内只拉起一个视频 let now = Date.now(); if (this.time && now - this.time < 3000) { resolve(null); return; } this.time = Date.now(); // if (this.callback) {//如果正在展示则返回无奖励 // resolve(null); // return; // } this.callback = resolve; platform.showRewardVideoAD(); })); } private static time: number; /** * 视频完播 */ public static onRewardVideoADComplete() { this.callback(g.adData); this.callback = null; } /** * 横幅展示 */ public static onBannerADShow() { g.adData.ad_type = 7; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); } /** * 全屏展示 */ public static onFullScreenADShow() { g.adData.ad_type = 9; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); } /** * 全屏完播 */ public static onFullScreenADComplete() { g.adData.ad_type = 8; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); } /** * 插屏展示 */ public static onInterstitalADShow() { g.adData.ad_type = 2; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); } /** * 信息流展示 */ public static onNativeExpressADShow() { g.adData.ad_type = 3; HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData.obj }); } } Http.onData = (data: any) => { if (!data) { return true; } if (data.code == HttpResponseCode.NoLogin) {//需要重新登录 localStorage.removeItem("account"); g.deviceData.needlogin = true; director.loadScene("launch"); return false; } else if (data.code == HttpErrorCode.SendDataError) {//数据错误 localStorage.removeItem("account"); g.deviceData.needlogin = true; director.loadScene("launch"); WindowSystem.showTips("数据异常,请重新登录"); return false; } else if (data.code == 0) {//尾巴验证 if (data.taskReceive !== undefined) {//如果任务完成 DataSystem.getData(TaskData).hasReceived = data.taskReceive; } if (data.checkBeAttack) {//玩家被攻击 DataSystem.getData(FightData).beAttack = data.checkBeAttack; DataSystem.getData(FightData).beAttack = DataSystem.getData(FightData).beAttack; } } return true; } Http.onKeyError = () => { localStorage.removeItem("account"); g.deviceData.needlogin = true; director.loadScene("launch"); } globalThis["g"] = g;