123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- 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: 102, //游戏版本号发版时需要核对
- 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,
- //已签到次数
- 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 == 1089) {
- Global.isMineEnter = true; //从我的小程序进入游戏
- }
- console.log('Global onShow' + JSON.stringify(query) + '======================================');
- if (query != undefined && query != null) {
- 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 = '';
- }
- }
- }
- // debugger;
- // 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;
- /// 关闭socket
- 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) {
- return {
- title: '猜猜他是谁?',
- imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/share_3.png',
- query: 'shareType=' + ShareAction.NONE,
- 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];
- return {
- title: shareObjct.title,
- imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
- query: 'shareType=' + ShareAction.NONE,
- success: function (res) {
- console.log('分享成功');
- // 分享成功上报
- SkillApi.report(2, (responseData) => {
- console.log('上报分享成功');
- },(error) => {
- });
- },
- fail: function (res) {
- // 转发失败
- console.log('取消或分享失败');
- },
- complete: function () {
- }
- }
- }
- });
- }
|