| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import { director, find } from "cc";
- import { Http } from "../core/net/Http";
- import { HttpSystem } from "../core/net/HttpSystem";
- import { WindowManager } from "../core/ui/window/WindowManager";
- import { Random } from "../core/utils/Random";
- import { ADData } from "./ADData";
- import { DeviceData } from "./DeviceData";
- import { GameData } from "./GameData";
- import { HttpErrorCode } from "./HttpErrorCode";
- import { ISJSB, platform } from "./platform";
- import { User } from "./User";
- import { WechatData } from "./WechatData";
- export class g {
- public static userData = new User();
- public static gameData = new GameData();
- public static deviceData = new DeviceData();
- public static adData = globalThis["adData"] || new ADData();
- public static wechatData = new WechatData();
- /**
- * 激励视频加载失败
- */
- public static onRewardVideoADError() {
- g.adData.ad_type = 5;
- HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
- this.callback(null);
- this.callback = null;
- }
- /**
- * 激励视频展⽰
- */
- public static onRewardVideoADShow() {
- g.adData.ad_type = 4;
- HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
- }
- /**
- * 放弃视频奖励
- */
- public static onRewardVideoADLoss() {
- this.callback(null);
- this.callback = null;
- }
- private static callback: (value: ADData) => void;
- /**
- * 显示激励视频
- * @returns
- */
- public static showRewardVideo() {
- return new Promise<ADData>((resolve => {
- if (!ISJSB) {//web版本直接返回成功
- resolve(g.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 });
- }
- /**
- * 全屏展示
- */
- public static onFullScreenADShow() {
- g.adData.ad_type = 9;
- HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
- }
- /**
- * 全屏完播
- */
- public static onFullScreenADComplete() {
- g.adData.ad_type = 8;
- HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
- }
- /**
- * 插屏展示
- */
- public static onInterstitalADShow() {
- g.adData.ad_type = 2;
- HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
- }
- /**
- * 信息流展示
- */
- public static onNativeExpressADShow() {
- g.adData.ad_type = 3;
- HttpSystem.send("/api/ad/videoLog", true, { adData: g.adData });
- }
- }
- Http.onData = (data: any) => {
- if (data.code == 1) {//需要重新登录
- g.deviceData.needlogin = true;
- director.loadScene("Launch");
- return false;
- }
- if (data.code == 0) {
- if (data.taskReceive !== undefined) {
- g.gameData.taskReceive = data.taskReceive;
- }
- if (data.threeDayTaskReceive !== undefined) {
- g.gameData.threeDayTaskReceive = data.threeDayTaskReceive;
- }
- }
- if (data.code == HttpErrorCode.ReloadData) {
- g.gameData.needReloadData = true;
- }
- return true;
- }
- Http.onKeyError = () => {
- g.deviceData.needlogin = true;
- director.loadScene("Launch");
- }
- globalThis["g"] = g;
|