Global.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const BuildingManager = require("../utils/BuildingManager");
  2. const ShareAction = require('./ShareAction');
  3. const Notikey = require('../utils/GameEnum').GameNotificationKey;
  4. const HomeApi = require("../net/HomeApi");
  5. const SkillApi = require("../net/SkillApi");
  6. const WeChat = require("../net/WeChat");
  7. const AlertManager = require('../utils/AlertManager');
  8. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  9. window.Global = {
  10. // 建筑管理
  11. BuildingManager: BuildingManager.instance,
  12. debug: true,
  13. ver: 101, //游戏版本号发版时需要核对
  14. isCheck: false,
  15. /**
  16. * 点击别人分享的链接需要进行的操作 查看群排行
  17. */
  18. shareType: ShareAction.NONE,
  19. /**
  20. * 点击别人分享的链接获取到这个用户的uid,默认-1
  21. */
  22. shareUid: -1,
  23. //SystemInfo
  24. os: 1,//1 android,2 ios
  25. channel: CC_WECHATGAME ? "weixin" : "LuciferChannel",
  26. user: null,
  27. /// 游戏是否退出到后台
  28. isOnHide: false,
  29. homeUpdate: true,
  30. wechatScoreKey: 'buildingLevel',
  31. // 开发中的城市Id
  32. devCityId: 1,
  33. buildRes: null,
  34. prefabsRes: null,
  35. starAvatarRes: null,
  36. needLogin: false,
  37. /// 最后一个缩短技能cd的技能等级
  38. rcdSkillLevel: 0,
  39. //是否已领取当天签到奖励
  40. isSignAward: false,
  41. //已签到次数
  42. signCount: 0,
  43. //分享出去的群id
  44. shareTicket: '',
  45. //通用网络请求提示框
  46. commonAlert: AlertManager
  47. };
  48. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  49. wx.onShow(({ query, shareTicket }) => {
  50. if (typeof wx.getUpdateManager === 'function') {
  51. const updateManager = wx.getUpdateManager()
  52. updateManager.onCheckForUpdate(function (res) {
  53. // 请求完新版本信息的回调
  54. console.log('hasUpdate: ' + JSON.stringify(res.hasUpdate));
  55. })
  56. updateManager.onUpdateReady(function () {
  57. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  58. updateManager.applyUpdate()
  59. })
  60. updateManager.onUpdateFailed(function () {
  61. // 新的版本下载失败
  62. })
  63. }
  64. console.log('Global onShow' + JSON.stringify(query) + '======================================');
  65. if (query != undefined && query != null) {
  66. Global.shareType = query.shareType;
  67. if (Global.shareType == ShareAction.SHOW_GROUP_RANK) {
  68. console.log('share ticket ' + shareTicket);
  69. if (shareTicket != undefined && shareTicket != null) {
  70. Global.shareTicket = shareTicket;
  71. GameEvent.fire(Notikey.GameShowGroupRank);//处理通过点击分享链接进入游戏的查看群排行榜
  72. } else {
  73. Global.shareTicket = '';
  74. }
  75. }
  76. }
  77. // debugger;
  78. // console.log(query.from, shareTicket);
  79. //// 如果是从后台到前台
  80. if (Global.isOnHide) {
  81. Global.isOnHide = false;
  82. /// 发通知更新跟定时器相关的数据
  83. GameEvent.fire(GameNotificationKey.GameShowNotificationKey);
  84. }
  85. });
  86. wx.onHide(() => {
  87. console.log('Global onHide ===================================');
  88. Global.isOnHide = true;
  89. cc.sys.localStorage.setItem("onHideTimestamp", Date.parse(new Date()));
  90. HomeApi.exitGame();
  91. });
  92. wx.showShareMenu({
  93. withShareTicket: true,
  94. success: function (res) {
  95. },
  96. fail: function (res) {
  97. },
  98. complete: function (res) {
  99. }
  100. });
  101. wx.onShareAppMessage(function (res) {
  102. // 用户点击了“转发”按钮
  103. if (res.from === 'button') {
  104. // 来自页面内转发按钮
  105. } else if (res.from === 'menu') {
  106. }
  107. let randomIndex = parseInt(Math.random()*(WeChat.shareArray.length),10);
  108. let shareObjct = WeChat.shareArray[randomIndex];
  109. return {
  110. title: shareObjct.title,
  111. imageUrl: 'https://pub.dwstatic.com/wxgame/taptapstar/share/' + shareObjct.icon,
  112. query: 'shareType=' + ShareAction.NONE,
  113. success: function (res) {
  114. console.log('分享成功');
  115. // 分享成功上报
  116. SkillApi.report(2, (responseData) => {
  117. console.log('上报分享成功');
  118. },(error) => {
  119. });
  120. },
  121. fail: function (res) {
  122. // 转发失败
  123. console.error(res);
  124. },
  125. complete: function (res) {
  126. }
  127. }
  128. });
  129. }