Init.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const weChat = require('./net/WeChat');
  2. const DWTool = require('./utils/DWTool');
  3. const Api = require('./net/Api');
  4. // const Ws = require('./net/Ws');
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. game: cc.Node,
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. onLoad() {
  12. // Ws.open();
  13. // setTimeout(() => {
  14. // Ws.emit('fuck', 111)
  15. // }, 2000)
  16. // Ws.on('getFuck', data => {
  17. // console.log(data);
  18. // })
  19. if (!CC_WECHATGAME) {
  20. Global.showLoginPage = false;
  21. Global.channel = 'LuciferChannel';
  22. Global.os = 1;
  23. Global.ver = 1;
  24. let uid = DWTool.getUrlParam('uid');
  25. let token = DWTool.getUrlParam('token');
  26. if (!uid && !token) {
  27. Global.user = {
  28. uid: 1,
  29. token: 'lucifer_test_token',
  30. nick: 'lucifer',
  31. avatar: "",
  32. gender: 1
  33. }
  34. } else {
  35. Global.user = {
  36. uid: uid,
  37. token: token,
  38. nick: "游客",
  39. avatar: "",
  40. gender: 1
  41. }
  42. }
  43. } else {
  44. switch (cc.sys.platform) {
  45. case cc.sys.WECHAT_GAME:
  46. Global.channel = 'weixin';
  47. break;
  48. case cc.sys.QQ_PLAY:
  49. Global.channel = 'qq';
  50. break;
  51. }
  52. }
  53. this.game.active = true;
  54. if (CC_WECHATGAME) {
  55. cc.game.setFrameRate(40); // 微信环境下强制游戏改为40帧的方法
  56. window.wx.postMessage({ //初始化的时候关闭子域刷新
  57. messageType: 8,
  58. });
  59. }
  60. console.log("Global: " + Global.channel);
  61. this.onUpdateGame();
  62. },
  63. start() {
  64. },
  65. onUpdateGame() {
  66. if (CC_WECHATGAME) {
  67. const updateManager = wx.getUpdateManager();
  68. updateManager.onCheckForUpdate(function (res) {
  69. // 请求完新版本信息的回调
  70. console.log(res.hasUpdate)
  71. })
  72. updateManager.onUpdateReady(function () {
  73. wx.showModal({
  74. title: '更新提示',
  75. content: '新版本已经准备好,是否重启应用?',
  76. success: function (res) {
  77. if (res.confirm) {
  78. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  79. updateManager.applyUpdate()
  80. }
  81. }
  82. })
  83. })
  84. updateManager.onUpdateFailed(function () {
  85. // 新的版本下载失败
  86. })
  87. }
  88. }
  89. // update (dt) {},
  90. });