Global.js 2.8 KB

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