var t = require; var e = module; var i = exports; var e = (this && this.__decorate) || function (t, e, i, s) { var o, a = arguments.length, n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s); else for (var r = t.length - 1; 0 <= r; r--) (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n); return 3 < a && n && Object.defineProperty(e, i, n), n; }, s = (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()); }); }; Object.defineProperty(i, "__esModule", {value: !0}), (i.RobotMgrView = void 0); const n = t("App"), o = t("List"), a = t("BaseView"), r = t("Toast"), l = (t("ViewConst"), t("GameDataMsr")), h = t("TipView"), {ccclass: c, property: d} = cc._decorator; t = class extends a.default { constructor() { super(...arguments), (this.IDBox = null), (this.itemList = null), (this.itemDatas = {nextId: 11e4, list: []}), (this.saveKey = "RobotMgr"); } initUI() { super.initUI(); var t = cc.sys.localStorage.getItem(this.saveKey); if (t) try { (this.itemDatas = JSON.parse(t)), (this.itemList.numItems = this.itemDatas.list.length); } catch (t) { this.itemList.numItems = 0; } this.IDBox.string = this.itemDatas.nextId + ""; } saveData() { cc.sys.localStorage.setItem(this.saveKey, JSON.stringify(this.itemDatas)); } onCreateNew() { var t = this.itemDatas.nextId++; this.IDBox.string = this.itemDatas.nextId + ""; var e = n.default.SaveManage.getAllAutoSaveData(); const i = JSON.parse(e); i[l.GameDataSaveKey.PLAYER_INFO].token = ""; t = {name: "机器人" + t, ability: 1, grade: 1, ID: t, archive: i}; this.itemDatas.list.push(t), (this.itemList.numItems = this.itemDatas.list.length), this.saveData(); } onImportData(t) { let e = t.target.getComponentInChildren(cc.EditBox); try { var i = e.string.includes("{") ? JSON.parse(e.string) : JSON.parse(n.default.StringUtil.unzip(e.string)); t: for (const e of i) { for (const t of this.itemDatas.list) if (t.name == e.name) continue t; this.itemDatas.list.push(e); } (this.itemList.numItems = this.itemDatas.list.length), this.saveData(), r.default.launch("导入完毕!"); } catch (t) { r.default.launch("导入失败!"), Log.error(t); } } onSaveRachiveToRobot(t, e) { const i = this.itemDatas.list[e]; n.default.ViewManager.open(13, { tipsStr: `\u662f\u5426\u5c06\u5f53\u524d\u5b58\u6863\u5b58\u5165ID\u4e3a:(${i.ID})\u7684\u673a\u5668\u4eba\u300a${i.name}\u300b\u4e2d`, leftBtnText: "确定", hasCloseBtn: !1, curState: h.TIPSTATE.SURE_CANCEL, leftFunc: () => { var t = n.default.SaveManage.getAllAutoSaveData(); const e = JSON.parse(t); (e[l.GameDataSaveKey.PLAYER_INFO].token = ""), (i.archive = e), (this.itemList.numItems = this.itemDatas.list.length), this.saveData(), r.default.launch("存入存档成功"); }, leftThisObj: this, rightBtnText: "取消", rightFunc: () => {}, rightThisObj: this }); } importText(a) { try { let t = "string" == typeof a.archive ? JSON.parse(a.archive) : a.archive, e = Object.keys(t), i = {}; for (const a of e) i[a.replace(/[\d]{8}/, "")] = t[a]; let s = (t = i)[l.GameDataSaveKey.PLAYER_INFO], o = n.default.GameDataMsr.playerInfo; (s.saveTime = n.default.DateUtils.Now()), (s.id = o.id), (s.account = o.account), (s.nickName = o.nickName), n.default.SaveManage.syncByData(t), (n.default.GameDataMsr.playerInfo.token = null), n.default.SaveManage.clearAllItem(), n.default.ViewManager.open(14, { tipsStr: "导入存档成功", hasCloseBtn: !1, curState: h.TIPSTATE.SURE, leftFunc: () => { n.default.Platform.resetGame(); }, leftThisObj: this }); } catch (t) { n.default.ViewManager.open(14, {tipsStr: "导入存档出错", curState: h.TIPSTATE.NO_SURE, hasCloseBtn: !0}); } } onEditArchiveName(e, i) { if (this.itemDatas.list[i].name != e.string) { var s = this.itemDatas.list.length; for (let t = 0; t < s; t++) if (this.itemDatas.list[t].name == e.string) return r.default.launch("修改失败,存档名不允许重复"), void (e.string = this.itemDatas.list[i].name); (this.itemDatas.list[i].name = e.string), this.saveData(); } } onEditAbility(t, e) { t = parseInt(t.string); isNaN(t) || t < 1 || 10 < t ? r.default.launch("请输入1~10的数字") : ((this.itemDatas.list[e].ability = t), this.saveData()); } onEditGrade(t, e) { t = parseInt(t.string); isNaN(t) || t < 1 || 10 < t ? r.default.launch("请输入1~10的数字") : ((this.itemDatas.list[e].grade = t), this.saveData()); } onOutputArchive(t, e) { var i = this.itemDatas.list, s = document.createElement("a"); (s.download = "机器人列表.json"), (s.style.display = "none"); i = new Blob([JSON.stringify(i, null, 4)]); (s.href = URL.createObjectURL(i)), document.body.appendChild(s), s.click(), document.body.removeChild(s); } onDeleteArchive(t, e) { e = parseInt(e); this.itemDatas.list.splice(e, 1), (this.itemList.numItems = this.itemDatas.list.length), this.saveData(); } onUploadRobotData(t, i) { return s(this, void 0, void 0, function* () { n.default.ViewManager.open(13, { tipsStr: "是否确定上传机器人数据", leftBtnText: "确定", hasCloseBtn: !1, curState: h.TIPSTATE.SURE_CANCEL, leftFunc: () => s(this, void 0, void 0, function* () { var t = this.itemDatas.list[i], e = `${n.default.ConfigManager.gameConf.serverInfos.game}/game/explore/createRobot/${t.ID}/${t.grade}/${t.ability}`, t = n.default.StringUtil.zipStr1(JSON.stringify(t)), t = yield n.default.Http.requestWithTokenAsync( e, t, n.default.GameDataMsr.playerInfo.token, "GET", "json" ); 0 === (null == t ? void 0 : t.code) ? r.default.launch("上传机器人数据成功") : (Log.error(t), r.default.launch("上传机器人数据失败")); }), leftThisObj: this, rightBtnText: "取消", rightFunc: () => {}, rightThisObj: this }); }); } onLoadArchive(t, e) { (e = parseInt(e)), (e = this.itemDatas.list[e]); this.importText(e); } onRenderItem(t, e) { let i = this.itemDatas.list[e], s = { edit: t.getChildByName("EditBox").getComponent(cc.EditBox), rank: t.getChildByName("AbilityBox").getComponent(cc.EditBox), ability: t.getChildByName("AbilityBox").getComponent(cc.EditBox), loadBtn: t.getChildByName("加载").getComponent(cc.Button), delBtn: t.getChildByName("删除").getComponent(cc.Button), saveBtn: t.getChildByName("保存").getComponent(cc.Button), uploadBtn: t.getChildByName("上传").getComponent(cc.Button) }; (s.edit.string = i.name), (t.getChildByName("IDLab").getComponent(cc.Label).string = "ID:" + i.ID), (s.loadBtn.clickEvents[0].customEventData = s.delBtn.clickEvents[0].customEventData = s.saveBtn.clickEvents[0].customEventData = s.uploadBtn.clickEvents[0].customEventData = s.edit.editingDidEnded[0].customEventData = s.ability.editingDidEnded[0].customEventData = s.rank.editingDidEnded[0].customEventData = e + ""); } }; e([d(cc.EditBox)], t.prototype, "IDBox", void 0), e([d({type: o.default})], t.prototype, "itemList", void 0), (t = e([c], t)), (i.RobotMgrView = t);