window.onerror = function handleErr(msg, url, line, colno, error) { try { let data = ""; let title = ""; if (error.stack) { let text = "----------------------------------------------------------------------------\n"; text = text + error.stack + "\n"; text = text + "-----------------------------------------------------------------------------\n"; title = "onerror.stack__" + url; data = error.stack; console.error('error.stack', text); } else { let text = "----------------------------------------------------------------------------\n"; text = text + url + " (" + line + ":" + colno + ")\n"; text = text + "-----------------------------------------------------------------------------\n"; title = "onerro.nostack__" + url; data = line + ":" + colno; console.error('error.stackelse', text); } let senddata = { "level": "error", "game": "tower", "message": data, } const Http = new XMLHttpRequest(); Http.responseType = "text"; const send_url = 'https://elktest.duiweize.com/api/logs/record'; Http.open("POST", send_url); Http.setRequestHeader("Content-Type", 'application/json;charset=UTF-8'); let str = JSON.stringify(senddata); let options = { default_key_size: 2048, default_public_exponent: new Uint8Array([0x01, 0x00, 0x01]) } let jsb = new window['JSEncrypt'](options) //公钥 var publicString = '-----BEGIN PUBLIC KEY-----\n' + 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuwz5V8wt525dMS+A9wOd\n' + 'NAjvKgxdyoXYuZSlAJEXLhvJlaXwFCKEsUg/qBBeo4nrRnwaFAjG7ItqbCWR9Ozv\n' + '6oY5tMYQnFFK82XkMGbKm1gG0z9vYKhcNYgHZHi+QKAw4tLLWXWO/QBTGelEXptD\n' + 'azlNmdM+8wHOknTcMuIyjc9Yo5qCoNsCJpA465vnREiBezBbKB3rSw+LmrRcZcFk\n' + 's8hmGtjpabcQ8sCxco7mRzVh6/DomNWfNm7hUP6shrrJirwjQtaS51grlScj8KhN\n' + 'h+kBoiI4Ad0Xz0GHasK5hAMf3sXDsN61r0An8KTfa/nsYSJDwogPIKkeKAsmw9Df\n' + 'EQIDAQAB\n' + '-----END PUBLIC KEY-----' jsb.setPublicKey(publicString) // 加密内容 str = jsb.encrypt(str) Http.send(str); } catch (e) { } return false; }; /** 加载页 */ import GameM from "./manager/GameM"; import AdM from "./manager/AdM"; import PoolMgr from "./manager/PoolMgr"; import { STORAGE_KEY } from "./datas/GlobalStorage"; import UiM, { PANEL_NAME } from "./manager/UiM"; import RuleNode from "./prefabs/RuleNode"; import DownLoadUI from "./ui/DownLoadUI"; import LogUtil from "./utils/LogUtil"; import PrefabManager from "./manager/PrefabManager"; import { Utils } from "./utils/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class Loader extends cc.Component { private res_dirArr = ['configs', 'gift'] //private res_dirArr = null @property(cc.Node) progressNode: cc.Node = null; @property(cc.Label) progressLabel: cc.Label = null; @property(cc.Sprite) progressSlider: cc.Sprite = null; @property(cc.Node) chuan: cc.Node = null; @property(cc.Node) tipNode: cc.Node = null; @property(cc.Label) tipTxt: cc.Label = null; hotUpdate = null loadComplete: boolean = false; hasTap = false private progressNum: number = 0; private progressRun: number = 0; private isLoadedScene: boolean = false; isLoaded: boolean = false; /** 是否检查热更 */ hasCheck = false hasCheckPrivacy = false /** 检查防沉迷 */ hasCheckAnti = false passAnti = false /** 检查安装更新 */ checkInstallUpdate = false /** 安装更新 */ installUpdate = false /** 安装更新显示 */ hasShowUpdate = false /** 忽略更新 */ ignoreInstall = false /** 检查是否清除本地热更资源 */ checkRemoveLocalHot = false public static Inst: Loader = null onLoad() { Loader.Inst = this this.hotUpdate = cc.find('Canvas').getComponent('HotUpdate') } start() { // // 开启调试 // cc.dynamicAtlasManager.showDebug(true); // // 关闭调试 // cc.dynamicAtlasManager.showDebug(false); cc.macro.ENABLE_MULTI_TOUCH = false; this.loadLocalRes() let loadIn = GameM.globalStorage.getStorage(STORAGE_KEY.firstLoadIn) if (loadIn == null) { loadIn = 1 GameM.globalStorage.setStorage(STORAGE_KEY.firstLoadIn, loadIn) AdM.onSendEvent('firstLoadIn', '第一次加载开始') } this.loadScene("Main"); //报错监听 //this.CheckError(); } /** 检查弹出隐私 */ checkPrivacy() { let hasAgree = GameM.globalStorage.getStorage(STORAGE_KEY.popRule) if (hasAgree != null) { GameM.commonData.passPrivacy = true } else { UiM.Instance.onPanel(PANEL_NAME.RuleNode, false, () => { UiM.Instance.ruleNode.getComponent(RuleNode).init(1) }) } } /** 检查认证和防沉迷 */ checkShowIdentification() { let value = GameM.globalStorage.getStorage(STORAGE_KEY.identification) if (value != null) { GameM.commonData.identification = value } console.log('GameM.commonData.identification ', GameM.commonData.identification) value = GameM.globalStorage.getStorage(STORAGE_KEY.todayPlayTime) if (value != null) { GameM.commonData.todayPlayTime = value } if (GameM.commonData.identification == 0) { if (UiM.Instance.CertificationNode == null) { UiM.Instance.onPanel(PANEL_NAME.CertificationNode) } } else if (GameM.commonData.identification == 2) { if (GameM.commonData.todayPlayTime >= 5400) { if (UiM.Instance.AntiAddictionNode == null) { UiM.Instance.onPanel(PANEL_NAME.AntiAddictionNode) } } else { this.passAnti = true } } else { this.passAnti = true } } /** 加载本地资源 */ loadLocalRes() { let resDirLength = this.res_dirArr.length let loadedResNum = 0 console.log('self.resDirLength ', resDirLength) this.res_dirArr.forEach(element => { cc.loader.loadResDir(element, (completedCount, totalCount, item) => { }, () => { loadedResNum++ console.log('this.loadedResNum ', loadedResNum) if (loadedResNum == resDirLength) { console.log('加载完成') PoolMgr.Inst.initPoolPrefab(); GameM.commonData.carCfg = cc.loader.getRes('configs/CarCfg').json GameM.commonData.buyNumCfg = cc.loader.getRes('configs/BuynumCfg').json GameM.commonData.roleCft = cc.loader.getRes('configs/RoleCfg').json GameM.commonData.TxtCft = cc.loader.getRes('configs/TxtCfg').json GameM.commonData.achieveCft = cc.loader.getRes('configs/AchieveCfg').json GameM.commonData.taskCft = cc.loader.getRes('configs/TaskCfg').json GameM.commonData.taskAwardCft = cc.loader.getRes('configs/TaskAwardCfg').json GameM.ClubData.clubShowShareInfo = cc.loader.getRes('configs/ClubShowShareInfoCfg').json //西游 GameM.commonData.fightCfg = cc.loader.getRes('configs/fightCfg').json GameM.commonData.fightRewardCfg = cc.loader.getRes('configs/fightRewardCfg').json GameM.commonData.fightRoleCfg = cc.loader.getRes('configs/fightRoleCfg').json GameM.commonData.fightRoleServerCfg = cc.loader.getRes('configs/fightRoleServerCfg').json GameM.commonData.buffCfg = cc.loader.getRes('configs/buffCfg').json GameM.commonData.buffbagCfg = cc.loader.getRes('configs/buffbagCfg').json GameM.commonData.mateCfg = cc.loader.getRes('configs/mateCfg').json GameM.commonData.mateTalentCfg = cc.loader.getRes('configs/mateTalentCfg').json GameM.commonData.mainBgCfg = cc.loader.getRes('configs/mainBgCfg').json if (CC_JSB) { AdM.getWxAppId(); } else { if (GameM.commonData.session_key != '' && GameM.commonData.uin != '') { console.log(">>>>>5uin:" + GameM.commonData.uin); GameM.httpM.getAccountInfo() } else { GameM.httpM.init(); } } this.isLoaded = true; console.log('MMM self.isLoaded') } }); }); } update(dt) { if (this.hasCheck && !this.hotUpdate.updateFinish) { if (this.hotUpdate._updating && this.hotUpdate.percent != 100) { this.progressSlider.fillRange = this.hotUpdate.percent * 0.01; this.progressLabel.string = '更新中 ' + this.hotUpdate.percent + "%"; } } else { this.progressRun += 0.03; let num = this.progressRun * 100 if (num >= 100) { num = 99 } this.progressLabel.string = '加载不耗流量 ' + parseInt(num + "") + "%"; this.chuan.parent.getComponent(cc.Sprite).fillRange = this.progressRun } if (cc.sys.os == cc.sys.OS_ANDROID) { if (GameM.commonData.appVersion == '') { return } else { if (!this.checkRemoveLocalHot) { let currentVersion = GameM.globalStorage.getStorage('currentVersion', 1) GameM.globalStorage.setStorage('currentVersion', GameM.commonData.appVersion) LogUtil.logV('MMM currentVersion >>> ', currentVersion) LogUtil.logV('MMM appVersion >>> ', GameM.commonData.appVersion) let path = localStorage.getItem('HotUpdateSearchPaths'); LogUtil.logV('MMM path >>> ', path) if (currentVersion) { let compareVer = Utils.versionCompareHandle(currentVersion, GameM.commonData.appVersion) if (compareVer < 0) { // 热更新的储存路径,如果旧版本中有多个,可能需要记录在列表中,全部清理 var storagePath = localStorage.getItem('HotUpdateSearchPaths'); if (storagePath) { let storageArr = JSON.parse(storagePath) let len = storageArr.length for (var i = 0; i < len; i++) { let path = storageArr.shift() jsb.fileUtils.removeDirectory(path); LogUtil.logV('MMM removeDirectory', storageArr[i]) } LogUtil.logV('MMM newStorageArr', storageArr) cc.sys.localStorage.removeItem('HotUpdateSearchPaths'); jsb.fileUtils.setSearchPaths(storageArr); cc.audioEngine.stopAll(); cc.game.restart(); } } } this.checkRemoveLocalHot = true LogUtil.logV('MMM storagePath', storagePath) return } } } if (!this.isLoadedScene && this.isLoaded && this.loadComplete && GameM.commonData.serverFinish && PrefabManager.Loaded) { if (GameM.commonData.popPrivacySwitch) { if (!this.hasCheckPrivacy) { this.hasCheckPrivacy = true this.checkPrivacy() } if (!GameM.commonData.passPrivacy) { return } } if (GameM.commonData.popIdentifySwitch) { if (!this.hasCheckAnti) { this.hasCheckAnti = true this.checkShowIdentification() } if (!this.passAnti) { return } } //检查安装更新 if (cc.sys.os == cc.sys.OS_ANDROID) { if (GameM.commonData.appVersion == '' || GameM.commonData.needForceUpdate == -1) { return } else { // if (!this.checkRemoveLocalHot) { // let currentVersion = GameM.globalStorage.getStorage('currentVersion', 1) // GameM.globalStorage.setStorage('currentVersion', GameM.commonData.appVersion) // LogUtil.logV('MMM currentVersion >>> ', currentVersion) // LogUtil.logV('MMM appVersion >>> ', GameM.commonData.appVersion) // let path = localStorage.getItem('HotUpdateSearchPaths'); // LogUtil.logV('MMM path >>> ', path) // if (currentVersion) { // let compareVer = Utils.versionCompareHandle(currentVersion, GameM.commonData.appVersion) // if (compareVer < 0) { // // 热更新的储存路径,如果旧版本中有多个,可能需要记录在列表中,全部清理 // var storagePath = localStorage.getItem('HotUpdateSearchPaths'); // if (storagePath) { // let storageArr = JSON.parse(storagePath) // let len = storageArr.length - 2 // for (var i = 0; i < len; i++) { // let path = storageArr.shift() // jsb.fileUtils.removeDirectory(path); // LogUtil.logV('MMM removeDirectory', storageArr[i]) // } // LogUtil.logV('MMM newStorageArr', storageArr) // cc.sys.localStorage.removeItem('HotUpdateSearchPaths'); // jsb.fileUtils.setSearchPaths(storageArr); // cc.audioEngine.stopAll(); // cc.game.restart(); // } // } // } // this.checkRemoveLocalHot = true // LogUtil.logV('MMM storagePath', storagePath) // return // } } if (!this.checkInstallUpdate) { // LogUtil.logV('MMM GameM.commonData.localVersion ', GameM.commonData.localVersion + ' installVersion ' + installVersion) if (GameM.commonData.needForceUpdate == 1) { this.installUpdate = true this.ignoreInstall = (GameM.globalStorage.getStorage('installVersion' + GameM.commonData.installVersion, 1) != null) } else { this.installUpdate = false } this.checkInstallUpdate = true return } //需要安装最新包 if (this.installUpdate) { //此版本没有 不再提醒 if (!this.ignoreInstall) { if (!this.hasShowUpdate) { this.hasShowUpdate = true UiM.Instance.onPanel(PANEL_NAME.DownLoadUI, false, () => { UiM.Instance.downLoadUI.getComponent(DownLoadUI).init(true) }) } //下次再说 if (!GameM.commonData.skipUpdate) { return } } } else { //检查热更新 if (!this.hasCheck) { if (window.jsb) { this.hotUpdate.checkUpdate() console.log('MMM checkUpdate ') } else { this.hotUpdate.updateFinish = true console.log('MMM updateFinish yse ') } this.hasCheck = true console.log('MMM updateFinish NO ') return } if (!this.hotUpdate.updateFinish) { console.log('MMM updateFinish state false') return } } } this.isLoadedScene = true; this.progressRun = 0.99 this.progressLabel.string = '加载不耗流量 ' + parseInt(99 + "") + "%"; this.chuan.parent.getComponent(cc.Sprite).fillRange = 1 console.log('MMM getloadscene ') //获取玩家数据后进入main cc.director.loadScene("Main"); } } loadScene(scene: string) { let time1 = (new Date()).getTime(); let self = this; cc.director.preloadScene(scene, (completedCount, totalCount, item) => { if (completedCount / totalCount > self.progressNum) { self.progressNum = completedCount / totalCount; } else { self.progressNum = 1 } }, () => { self.loadComplete = true; console.log("---------->SceneLoaded:" + ((new Date()).getTime() - time1) * 0.001); }) } /** * 提示语显示 */ PlayTip(content: string) { if (!this.tipNode) { return } this.tipNode.stopAllActions(); this.tipNode.setPosition(cc.v2(0, 0)); this.tipNode.active = true; this.tipNode.opacity = 255; this.tipTxt.string = content; let ac1 = cc.moveTo(0.35, cc.v2(0, this.node.height / 4)).easing(cc.easeSineOut()); let wait = cc.delayTime(1.5); let fade = cc.fadeOut(1).easing(cc.easeQuinticActionIn()); let backcall = cc.callFunc(() => this.tipNode.active = false); let total = cc.sequence(ac1, wait, fade, backcall); this.tipNode.runAction(total); } //CheckError() { //} }