import Main from "../Main" import AdM from "../manager/AdM" import GameM, { AUDIO_TYPE } from "../manager/GameM" import UiM, { PANEL_NAME } from "../manager/UiM" import EffectNode from "../ui/EffectNode" import MoreGameNode from "../ui/MoreGameNode" import LogUtil from "../utils/LogUtil" import { Utils } from "../utils/Utils" import { CFG_SERVER, HTTP_TYPE } from "./CommonData" /** 彩蛋数据类 */ export default class MoreGameData { /**推荐游戏信息 */ moreGameList = null public interProperTotal = 0; private static instance: MoreGameData = null private static downLoadTask: Map = null static get Instance(): MoreGameData { if (!this.instance) { this.downLoadTask = new Map() this.instance = new MoreGameData() } return this.instance } private testData = { "normal": [ { "nebulaAppId": "wxd2e694c55d457ded", "title": "爱上切水果", "introduction": "切水果、切水果、切、切、切!", "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/CutFruit.apk", "packageName": "com.aries.asqsg.mz", "icon": "https://oss.duiweize.com/fission/5vp7CPeadkABlgIe.png", "banner": "https://oss.duiweize.com/fission/EXrqiYF6BkC1ZsZf.png", }, { "nebulaAppId": "wx74fee17e08a29836", "title": "炮火掠夺", "introduction": "大炮一响,黄金万两!", "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/FirePillage.apk", "packageName": "com.aries.firepillage.mz", "icon": "https://oss.duiweize.com/fission/BZ9ZUicxgCbWb33D.png", "banner": "https://oss.duiweize.com/fission/vGPWCE2tuGZwLSJH.png", } ], "banner": [ { "nebulaAppId": "wx07895e2f78748daf", "title": "豪车大富翁", "introduction": "豪车、金钱、美女,你要的这里都有!", "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/HundredsOfMillions.apk", "packageName": "org.cocos2d.hundredsofmillion.mk.mz", "icon": "https://oss.duiweize.com/fission/fviQN9OpUmmqpTjU.png", "banner": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png", }, { "nebulaAppId": "wx22b3f0f8005f0e51", "title": "航海传奇", "introduction": " 战舰、短裙、红包,你想要的都有!", "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/LegendOfNavigation.apk", "packageName": "com.aries.hhcq.mz", "icon": "https://oss.duiweize.com/fission/ZqDsgbj9PT94RcG0.png", "banner": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png", } ] } sendRecommendList() { GameM.httpM.sendDatas(HTTP_TYPE.recommendList, null, MoreGameData.Instance.getRecommendList.bind(this)); } getRecommendList(data) { // LogUtil.logV("getRecommendList ", data) this.moreGameList = data // //test // this.moreGameList = this.testData if (cc.isValid(UiM.Instance.moreGameNode)) { UiM.Instance.moreGameNode.getComponent(MoreGameNode).initView() } if (cc.isValid(UiM.Instance.hallNode)) { let main = UiM.Instance.hallNode.getComponent(Main) if (this.moreGameList == null || this.moreGameList == undefined) { main.moreGameBtn.node.active = false return } if ((this.moreGameList.banner == null || this.moreGameList.banner == undefined || this.moreGameList.banner.length == 0) && (this.moreGameList.normal == null || this.moreGameList.normal == undefined || this.moreGameList.normal.length == 0)) { main.moreGameBtn.node.active = false return } if (cc.sys.platform == cc.sys.ANDROID) { main.setMoreGameSp(this.moreGameList.normal) } main.moreGameBtn.node.active = true } } /**上报 */ sendAppDownloadLog(downLoadAppId: string) { GameM.httpM.sendDatas(HTTP_TYPE.appDownloadLog, { "downloadAppId": downLoadAppId }, MoreGameData.Instance.getAppDownloadLog.bind(this)); } getAppDownloadLog(data) { LogUtil.logV("getAppDownloadLog", data) this.moreGameList = data } // nebulaAppId: wx07895e2f78748das // title: 测试3 // introduction: 阿达大厦大 // downloadUrl: htt://www.baidu.com // packageName: // icon: https://oss.duiweize.com/fission/5HVo76AZCBEBjjAz.png // banner: https://oss.duiweize.com/fission/Q2xrr3pJRcpoRhz3.png // type: 2 // sort: 2 createNewTask(data): DownloadTaskClazz { let name = data.nebulaAppId + ".apk" let url = data.downloadUrl let packageName = data.packageName if (packageName != "") { let isExist = AdM.canStartGame(packageName, true) if (isExist) { AdM.onSendEvent('hutuiEventLaunch_' + data.nebulaAppId, "互推启动" + data.title, 'hutuiEventLaunch') //判断在原生环境下存在就直接启动 return null } } if (jsb.fileUtils.isFileExist(jsb.fileUtils.getWritablePath() + name)) { AdM.installApk(jsb.fileUtils.getWritablePath() + name) return null } if (MoreGameData.downLoadTask[data.nebulaAppId]) { EffectNode.instance.PlayTipSimple('正在下载中...') return null } EffectNode.instance.PlayTipSimple('开始下载...') let downLoadTask = new DownloadTaskClazz(0, 0, data.nebulaAppId, null) let curTask = Utils.downFile2Local(url, data.nebulaAppId + ".apk", (locaPath) => { LogUtil.logV("sendAppDownloadLog", "success") downLoadTask.progress = -2 this.sendAppDownloadLog(data.nebulaAppId) setTimeout(() => { AdM.installApk(jsb.fileUtils.getWritablePath() + name) }, 1) }, () => { downLoadTask.progress = -1 MoreGameData.downLoadTask[data.nebulaAppId] = null EffectNode.instance.PlayTip('下载失败,请稍后再试') }, (task: jsb.DownloaderTask, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) => { downLoadTask.progress = bytesReceived downLoadTask.totalBytesReceives = totalBytesReceived }) downLoadTask.downloadTask = curTask MoreGameData.downLoadTask[data.nebulaAppId] = downLoadTask AdM.onSendEvent('hutuiEventDown_' + data.nebulaAppId, "互推下载" + data.title, 'hutuiEventDown') return downLoadTask } getTaskInfo(appId): DownloadTaskClazz { // for(let entry of t) return MoreGameData.downLoadTask[appId] } /** 随机获取信息流位游戏 展示在十倍领取*/ getRandomSteam() { if (!this.moreGameList) { return null } let index = Utils.rnd(0, this.moreGameList.stream.length - 1) let data = this.moreGameList.stream[index] return data } /** 随机获取底部位游戏 展示在更多游戏界面列表小图*/ getRandomNormal() { if (!this.moreGameList) { return null } let index = Utils.rnd(0, this.moreGameList.normal.length - 1) let data = this.moreGameList.normal[index] return data } getRandomInter() { if (!this.moreGameList) { return null } let len = this.moreGameList.plug.length let proper = this.interProperTotal * Math.random(); console.log('proper ', proper) let add = 0 let index = 0 for (var j = 0; j < len; j++) { add += this.moreGameList.plug[j].probability if (proper <= add) { index = j break } } let data = this.moreGameList.plug[index] return data } } /** 下载任务 */ class DownloadTaskClazz { private _progress = 0 private _totalBytesReceives = 0 private _nebulaAppId = "" private _downloadTask = null constructor(progress, totalBytesReceives, nebulaAppId, downloadTask) { this._progress = progress this._totalBytesReceives = totalBytesReceives this._nebulaAppId = nebulaAppId this._downloadTask = downloadTask } public get progress(): number { return this._progress } public set progress(progress: number) { this._progress = progress } public get totalBytesReceives(): number { return this._totalBytesReceives } public set totalBytesReceives(totalBytesReceives: number) { this._totalBytesReceives = totalBytesReceives } public get downloadTask(): any { return this._downloadTask } public set downloadTask(downloadTask: any) { this._downloadTask = downloadTask } }