var t = require; var e = module; var i = (this && this.__awaiter) || function (t, n, r, l) { return new (r = r || Promise)(function (i, e) { function s(t) { try { a(l.next(t)); } catch (t) { e(t); } } function o(t) { try { a(l.throw(t)); } catch (t) { e(t); } } function a(t) { var e; t.done ? i(t.value) : ((e = t.value) instanceof r ? e : new r(function (t) { t(e); }) ).then(s, o); } a((l = l.apply(t, n || [])).next()); }); }; Date.prototype.Format = function (t) { var e, i = { "M+": this.getMonth() + 1, "d+": this.getDate(), "h+": this.getHours(), "m+": this.getMinutes(), "s+": this.getSeconds(), "q+": Math.floor((this.getMonth() + 3) / 3), S: this.getMilliseconds() }; for (e in (/(y+)/.test(t) && (t = t.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))), i)) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); return t; }; class n { constructor() { (this.max_size = 512e3), (this.str = ""), (this.warnStr = ""), (this._date = new Date()), (this.saveIndex = 0), (this.maxCache = 10); var t = cc.sys.localStorage.getItem("saveIndex"); t && ((this.saveIndex = parseInt(t)), (t = "logCache" + this.getCurIndex()), (t = cc.sys.localStorage.getItem(t)) && (this.str = `${t}\n\n/--------------------\u767b\u5f55${this._date.Format("MM-dd hh:mm:ss: ")}----/`)), (n._instance = this).init(); } static getInstance() { return this._instance; } static trace(t, ...e) { console.log(t, ...e); } static warn(t, ...e) { console.warn(t, ...e); } static error(t, ...e) { cc.error(t, ...e); } static debug(t) {} onOutputArchive(t) { var e = document.createElement("a"); (e.download = new Date().Format("错误日志-(MM-dd hh:mm:ss)") + ".log"), (e.style.display = "none"); t = new Blob([JSON.stringify(t, null, 4)]); (e.href = URL.createObjectURL(t)), document.body.appendChild(e), e.click(), document.body.removeChild(e); } sendToNative(o) { return i(this, void 0, void 0, function* () { let t = cc.sys.localStorage.getItem("bdlm_game"); t || ((t = Date.now() + "" + Math.floor(1e5 * Math.random())), cc.sys.localStorage.setItem("bdlm_game", t)); let e = `/-------------\u7cbe\u7075\u5408\u6210 id:${t}, pId:${o}-----------/`; if (0 <= this.saveIndex) { for (let t = Math.max(this.saveIndex - this.maxCache + 1, 0); t <= this.saveIndex; t++) { var i = "logCache" + (t % this.maxCache), s = cc.sys.localStorage.getItem(i); s && ((e += s), cc.sys.localStorage.setItem(i, "")); } this.saveIndex = 0; } return this.onOutputArchive(e), (this.str = ""), t; }); } requestAsync(t, e, a = 1e4) { return new Promise((i, s) => { var o = new XMLHttpRequest(); (o.timeout = a), (o.onerror = t => { s(t), (s = null); }), (o.ontimeout = () => { s("请求超时"), (s = null); }), (o.onreadystatechange = function () { var t, e; 4 == o.readyState && ((t = 400 <= o.status || 0 == o.status), (e = o.responseText), t ? (n.error(o.status), s(o.status)) : i(e)); }), o.open("POST", t, !0), o.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), o.send(e); }); } onConnect() { this._log("onConnect"), (this.isConnect = !0); } onClose() {} onError() { this._log("onError"); } onSocketData(t) {} initWebSocket() {} static init() {} init() { { let t = function (t, e, i) { console.log("错误"); i = JSON.stringify({file: e, line: i, err: t}, null, 4); return ( n._instance.addLog(i), console.error("捕捉到错误", t), s.cacheCurLog(), alert("捕捉到错误!!!!!,请联系开发者"), !0 ); }, s = this; cc.sys.isNative ? (jsb.onError((t, e, i) => { i = JSON.stringify({line: t, err: e, file: i}, null, 4); return n._instance.addLog(i), s.cacheCurLog(), !0; }), (window.__errorHandler = function (t, e, i) { i = JSON.stringify({file: t, line: e, err: i}, null, 4); return n._instance.addLog(i), s.cacheCurLog(), !0; })) : ((window.onerror = t), window.addEventListener("unhandledrejection", function (t) { t = JSON.stringify({line: t.reason.message, err: t.reason.stack}, null, 4); return n._instance.addLog(t), cc.error(t), alert("捕捉到错误!!!!!,请联系开发者"), !0; })); } cc.game.on(cc.game.EVENT_HIDE, this.onHide, this), cc.game.on(cc.game.EVENT_SHOW, this.onShow, this); } onHide() { this.cacheCurLog(); } onShow() {} sendLog(t) { this._date.setTime(Date.now()), this.requestAsync( "https://www.gzqidong.cn/test/SaveLog1.php", `info=${encodeURIComponent(this._date.Format("hh:mm:ss: ") + t)}` ); } getCurIndex() { return this.saveIndex % this.maxCache; } cacheCurLog() { console.log("缓存log"), cc.sys.localStorage.setItem("logCache" + this.getCurIndex(), this.str), cc.sys.localStorage.setItem("saveIndex", this.saveIndex + ""); } addLog(t) {} } window.Log = n;