Global.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: 100,
  18. os: 1,//1 android,2 ios
  19. channel: "weixin",
  20. user: null,
  21. homeUpdate: true,
  22. wechatScoreKey: 'starCount',
  23. // 开发中的城市Id
  24. devCityId: 1,
  25. buildRes: null,
  26. needLogin: false,
  27. };
  28. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  29. wx.onShow(({ query, shareTicket }) => {
  30. if (typeof wx.getUpdateManager === 'function') {
  31. const updateManager = wx.getUpdateManager()
  32. updateManager.onCheckForUpdate(function (res) {
  33. // 请求完新版本信息的回调
  34. console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
  35. })
  36. updateManager.onUpdateReady(function () {
  37. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  38. updateManager.applyUpdate()
  39. })
  40. updateManager.onUpdateFailed(function () {
  41. // 新的版本下载失败
  42. })
  43. }
  44. console.log('Global onShow' + JSON.stringify(query) + '======================================');
  45. if (query != undefined && query != null) {
  46. if (query.uid != undefined) {
  47. // Global.processShareAction(query.uid, query.shareType);
  48. Global.shareUid = query.uid;
  49. Global.shareType = query.shareType;
  50. GameEvent.fire(Notikey.ProcessShareAction);//处理通过点击分享链接进入游戏的各种操作,加好友.....
  51. }
  52. if (shareTicket != undefined && shareTicket != null) {
  53. }
  54. }
  55. let onShowTimestamp = Date.parse(new Date());
  56. let onHideTimestamp = cc.sys.localStorage.getItem("onHideTimestamp");
  57. if (onHideTimestamp !== 0) {
  58. let sec = (onShowTimestamp - onHideTimestamp) / 1000;
  59. if (sec > 180) {
  60. GameEvent.fire(Notikey.HomeReloadData);
  61. } else {
  62. GameEvent.fire(Notikey.HomeUpdateData, sec);
  63. }
  64. }
  65. console.log("onShowTimestamp: " + onShowTimestamp);
  66. console.log("onHideTimestamp: " + onHideTimestamp);
  67. });
  68. wx.onHide(() => {
  69. console.log('Global onHide ===================================');
  70. cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
  71. });
  72. }