const BuildingManager = require("../utils/BuildingManager"); const ShareAction = require('./ShareAction'); const HomeApi = require("../net/HomeApi"); const SkillApi = require("../net/SkillApi"); const WeChat = require("../net/WeChat"); const AlertManager = require('../utils/AlertManager'); const {GameNotificationKey, WechatShareType } = require('../utils/GameEnum'); const GameModule = require("../utils/GameModule"); window.Global = { // 建筑管理 BuildingManager: BuildingManager.instance, debug: true, ver: 114, //游戏版本号发版时需要核对 isCheck: false, isMineEnter: false, /** * 点击别人分享的链接需要进行的操作 查看群排行 */ shareType: ShareAction.NONE, /** * 点击别人分享的链接获取到这个用户的uid,默认-1 */ shareUid: -1, //SystemInfo os: 1,//1 android,2 ios channel: CC_WECHATGAME ? "weixin" : "LuciferChannel", user: null, /// 游戏是否退出到后台 isOnHide: false, homeUpdate: true, wechatScoreKey: 'buildingLevel', // 开发中的城市Id devCityId: 1, buildRes: null, prefabsRes: null, starAvatarRes: null, starSpineRes: null, needLogin: false, /// 最后一个缩短技能cd的技能等级 rcdSkillLevel: 0, //是否已领取当天签到奖励 isSignAward: false, //是否已领取我的小程序奖励 appletAward: false, //判断是否使用本地数据 localData: false, //已签到次数 signCount: 0, //分享出去的群id shareTicket: '', //通用网络请求提示框 commonAlert: AlertManager, //是否点击过分享 clickShare: false, gameShareType: WechatShareType.None, //当前设备屏幕尺寸 winSize: {height: 0, width: 0} }; if (cc.sys.platform === cc.sys.WECHAT_GAME) { wx.onShow(({scene, query, shareTicket }) => { if (typeof wx.getUpdateManager === 'function') { const updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate)); }) updateManager.onUpdateReady(function () { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate(); }) updateManager.onUpdateFailed(function () { // 新的版本下载失败 }) } //进入游戏的场景值 console.log('scene ' + scene + '==============================game ==============================='); if (scene == 1104) { Global.isMineEnter = true; //从我的小程序进入游戏 } else { Global.isMineEnter = false; //从我的小程序进入游戏 } console.log('Global onShow' + JSON.stringify(query) + '======================================'); if (query != undefined && query != null) { if (typeof query == "string") { query = JSON.parse(query); } Global.shareType = query.shareType; if (Global.shareType == ShareAction.SHOW_GROUP_RANK) { if (shareTicket != undefined && shareTicket != null) { Global.shareTicket = shareTicket; GameEvent.fire(GameNotificationKey.GameShowGroupRank);//处理通过点击分享链接进入游戏的查看群排行榜 } else { Global.shareTicket = ''; } } if (query.uid != undefined && Global.shareType == ShareAction.INVITE_FRIEND) { Global.shareUid = query.uid; GameEvent.fire(GameNotificationKey.ProcessShareAction);//处理通过点击分享链接进入游戏的各种操作,加好友..... } } // console.log(query.from, shareTicket); //// 如果是从后台到前台 if (Global.isOnHide) { Global.isOnHide = false; //客户端优先刷新技能使用情况 GameEvent.fire(GameNotificationKey.GameSkillOnHide); /// 发通知更新跟定时器相关的数据 GameEvent.fire(GameNotificationKey.GameShowNotificationKey); if (Global.clickShare) { GameEvent.fire(GameNotificationKey.ShowShareAction, Global.gameShareType); Global.clickShare = false; Global.gameShareType = WechatShareType.None; SkillApi.report(2, (responseData) => { },(error) => { }); } } if (GameModule.audioMng) { GameModule.audioMng.playBgm(); } }); wx.onHide(() => { console.log('Global onHide ==================================='); Global.isOnHide = true; if (GameModule.userInfo) { GameModule.userInfo.doReport(); } // /// 关闭socket 如果socket是打开的状态 其它的状态就不管 打开之后直接重连 && Global._wxSocket.readyState == 'open' // if (Global._wxSocket != undefined && Global._wxSocket != null ) { // Global._wxSocket.close(); // } cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date())); HomeApi.exitGame(); if (GameModule.audioMng) { GameModule.audioMng.stopAll(); } }); wx.showShareMenu({ withShareTicket: true, success: function (res) { }, fail: function (res) { }, complete: function (res) { } }); wx.onShareAppMessage(function (res) { // 用户点击了“转发”按钮 if (res.from === 'button') { // 来自页面内转发按钮 } else if (res.from === 'menu') { } if (Global.isCheck) { var uid = -1; if (Global.user != undefined && Global.user.uid != undefined) { uid = Global.user.uid; } return { title: '猜猜他是谁?', imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share_3.png', query: 'uid=' + uid + '&shareType=' + ShareAction.INVITE_FRIEND, success: function (res) { console.log('分享成功'); // 分享成功上报 SkillApi.report(2, (responseData) => { console.log('上报分享成功'); },(error) => { }); }, fail: function (res) { // 转发失败 console.log('取消或分享失败'); }, complete: function () { } } } else { let randomIndex = parseInt(Math.random()*(WeChat.shareArray.length),10); let shareObjct = WeChat.shareArray[randomIndex]; var uid = -1; if (Global.user != undefined && Global.user.uid != undefined) { uid = Global.user.uid; } return { title: shareObjct.title, imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon, query: 'uid=' + uid + '&shareType=' + ShareAction.INVITE_FRIEND, success: function (res) { console.log('分享成功'); // 分享成功上报 SkillApi.report(2, (responseData) => { console.log('上报分享成功'); },(error) => { }); }, fail: function (res) { // 转发失败 console.log('取消或分享失败'); }, complete: function () { } } } }); }