| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- 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() {
- //}
- }
|