| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- 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<string, DownloadTaskClazz> = null
- static get Instance(): MoreGameData {
- if (!this.instance) {
- this.downLoadTask = new Map<string, any>()
- 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
- }
- }
|