Global.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const BuildingManager = require("../utils/BuildingManager");
  2. const ShareAction = require('./ShareAction');
  3. const Notikey = require('../utils/GameEnum').GameNotificationKey;
  4. const DWTool = require('./utils/DWTool');
  5. var Global = Global || {}
  6. Global = {
  7. // 建筑管理
  8. BuildingManager: BuildingManager.instance,
  9. debug: false,
  10. /**
  11. * 点击别人分享的链接需要进行的操作 加好友
  12. */
  13. shareType: ShareAction.NONE,
  14. /**
  15. * 点击别人分享的链接获取到这个用户的uid,默认-1
  16. */
  17. shareUid: -1,
  18. //SystemInfo
  19. ver: 1,
  20. os: 1,//1 android,2 ios
  21. channel: CC_WECHATGAME ? "weixin" : "LuciferChannel",
  22. user: null,
  23. homeUpdate: true,
  24. wechatScoreKey: 'starCount',
  25. // 开发中的城市Id
  26. devCityId: 1,
  27. buildRes: null,
  28. needLogin: false,
  29. friendList: []
  30. };
  31. // 开发模式下快速切换 正式 or 测试 环境
  32. if(CC_DEV && DWTool.getUrlParam('debug') != null) {
  33. Global.debug = !!~~DWTool.getUrlParam('debug');
  34. }
  35. Global.socketUrl = Global.debug ?
  36. 'wss://test-message-allstar.duowan.com/connect' : 'wss://message-allstar.duowan.com/connect';
  37. window.Global = Global;
  38. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  39. wx.onShow(({ query, shareTicket }) => {
  40. // if (typeof wx.getUpdateManager === 'function') {
  41. // const updateManager = wx.getUpdateManager()
  42. // updateManager.onCheckForUpdate(function (res) {
  43. // // 请求完新版本信息的回调
  44. // console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
  45. // })
  46. // updateManager.onUpdateReady(function () {
  47. // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  48. // updateManager.applyUpdate()
  49. // })
  50. // updateManager.onUpdateFailed(function () {
  51. // // 新的版本下载失败
  52. // })
  53. // }
  54. console.log('Global onShow' + JSON.stringify(query) + '======================================');
  55. if (query != undefined && query != null) {
  56. if (query.uid != undefined) {
  57. // Global.processShareAction(query.uid, query.shareType);
  58. Global.shareUid = query.uid;
  59. Global.shareType = query.shareType;
  60. GameEvent.fire(Notikey.ProcessShareAction);//处理通过点击分享链接进入游戏的各种操作,加好友.....
  61. }
  62. if (shareTicket != undefined && shareTicket != null) {
  63. }
  64. }
  65. let onShowTimestamp = Date.parse(new Date());
  66. let onHideTimestamp = cc.sys.localStorage.getItem("onHideTimestamp");
  67. if (onHideTimestamp !== 0) {
  68. let sec = (onShowTimestamp - onHideTimestamp) / 1000;
  69. if (sec > 180) {
  70. GameEvent.fire(Notikey.HomeReloadData);
  71. } else {
  72. GameEvent.fire(Notikey.HomeUpdateData, sec);
  73. }
  74. }
  75. console.log("onShowTimestamp: " + onShowTimestamp);
  76. console.log("onHideTimestamp: " + onHideTimestamp);
  77. });
  78. wx.onHide(() => {
  79. console.log('Global onHide ===================================');
  80. cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
  81. });
  82. }