Global.js 3.0 KB

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