RobotMgrView.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var e =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. },
  16. s =
  17. (this && this.__awaiter) ||
  18. function (t, n, r, l) {
  19. return new (r = r || Promise)(function (i, e) {
  20. function s(t) {
  21. try {
  22. a(l.next(t));
  23. } catch (t) {
  24. e(t);
  25. }
  26. }
  27. function o(t) {
  28. try {
  29. a(l.throw(t));
  30. } catch (t) {
  31. e(t);
  32. }
  33. }
  34. function a(t) {
  35. var e;
  36. t.done
  37. ? i(t.value)
  38. : ((e = t.value) instanceof r
  39. ? e
  40. : new r(function (t) {
  41. t(e);
  42. })
  43. ).then(s, o);
  44. }
  45. a((l = l.apply(t, n || [])).next());
  46. });
  47. };
  48. Object.defineProperty(i, "__esModule", {value: !0}), (i.RobotMgrView = void 0);
  49. const n = t("App"),
  50. o = t("List"),
  51. a = t("BaseView"),
  52. r = t("Toast"),
  53. l = (t("ViewConst"), t("GameDataMsr")),
  54. h = t("TipView"),
  55. {ccclass: c, property: d} = cc._decorator;
  56. t = class extends a.default {
  57. constructor() {
  58. super(...arguments),
  59. (this.IDBox = null),
  60. (this.itemList = null),
  61. (this.itemDatas = {nextId: 11e4, list: []}),
  62. (this.saveKey = "RobotMgr");
  63. }
  64. initUI() {
  65. super.initUI();
  66. var t = cc.sys.localStorage.getItem(this.saveKey);
  67. if (t)
  68. try {
  69. (this.itemDatas = JSON.parse(t)), (this.itemList.numItems = this.itemDatas.list.length);
  70. } catch (t) {
  71. this.itemList.numItems = 0;
  72. }
  73. this.IDBox.string = this.itemDatas.nextId + "";
  74. }
  75. saveData() {
  76. cc.sys.localStorage.setItem(this.saveKey, JSON.stringify(this.itemDatas));
  77. }
  78. onCreateNew() {
  79. var t = this.itemDatas.nextId++;
  80. this.IDBox.string = this.itemDatas.nextId + "";
  81. var e = n.default.SaveManage.getAllAutoSaveData();
  82. const i = JSON.parse(e);
  83. i[l.GameDataSaveKey.PLAYER_INFO].token = "";
  84. t = {name: "机器人" + t, ability: 1, grade: 1, ID: t, archive: i};
  85. this.itemDatas.list.push(t), (this.itemList.numItems = this.itemDatas.list.length), this.saveData();
  86. }
  87. onImportData(t) {
  88. let e = t.target.getComponentInChildren(cc.EditBox);
  89. try {
  90. var i = e.string.includes("{") ? JSON.parse(e.string) : JSON.parse(n.default.StringUtil.unzip(e.string));
  91. t: for (const e of i) {
  92. for (const t of this.itemDatas.list) if (t.name == e.name) continue t;
  93. this.itemDatas.list.push(e);
  94. }
  95. (this.itemList.numItems = this.itemDatas.list.length), this.saveData(), r.default.launch("导入完毕!");
  96. } catch (t) {
  97. r.default.launch("导入失败!"), Log.error(t);
  98. }
  99. }
  100. onSaveRachiveToRobot(t, e) {
  101. const i = this.itemDatas.list[e];
  102. n.default.ViewManager.open(13, {
  103. tipsStr: `\u662f\u5426\u5c06\u5f53\u524d\u5b58\u6863\u5b58\u5165ID\u4e3a:(${i.ID})\u7684\u673a\u5668\u4eba\u300a${i.name}\u300b\u4e2d`,
  104. leftBtnText: "确定",
  105. hasCloseBtn: !1,
  106. curState: h.TIPSTATE.SURE_CANCEL,
  107. leftFunc: () => {
  108. var t = n.default.SaveManage.getAllAutoSaveData();
  109. const e = JSON.parse(t);
  110. (e[l.GameDataSaveKey.PLAYER_INFO].token = ""),
  111. (i.archive = e),
  112. (this.itemList.numItems = this.itemDatas.list.length),
  113. this.saveData(),
  114. r.default.launch("存入存档成功");
  115. },
  116. leftThisObj: this,
  117. rightBtnText: "取消",
  118. rightFunc: () => {},
  119. rightThisObj: this
  120. });
  121. }
  122. importText(a) {
  123. try {
  124. let t = "string" == typeof a.archive ? JSON.parse(a.archive) : a.archive,
  125. e = Object.keys(t),
  126. i = {};
  127. for (const a of e) i[a.replace(/[\d]{8}/, "")] = t[a];
  128. let s = (t = i)[l.GameDataSaveKey.PLAYER_INFO],
  129. o = n.default.GameDataMsr.playerInfo;
  130. (s.saveTime = n.default.DateUtils.Now()),
  131. (s.id = o.id),
  132. (s.account = o.account),
  133. (s.nickName = o.nickName),
  134. n.default.SaveManage.syncByData(t),
  135. (n.default.GameDataMsr.playerInfo.token = null),
  136. n.default.SaveManage.clearAllItem(),
  137. n.default.ViewManager.open(14, {
  138. tipsStr: "导入存档成功",
  139. hasCloseBtn: !1,
  140. curState: h.TIPSTATE.SURE,
  141. leftFunc: () => {
  142. n.default.Platform.resetGame();
  143. },
  144. leftThisObj: this
  145. });
  146. } catch (t) {
  147. n.default.ViewManager.open(14, {tipsStr: "导入存档出错", curState: h.TIPSTATE.NO_SURE, hasCloseBtn: !0});
  148. }
  149. }
  150. onEditArchiveName(e, i) {
  151. if (this.itemDatas.list[i].name != e.string) {
  152. var s = this.itemDatas.list.length;
  153. for (let t = 0; t < s; t++)
  154. if (this.itemDatas.list[t].name == e.string)
  155. return r.default.launch("修改失败,存档名不允许重复"), void (e.string = this.itemDatas.list[i].name);
  156. (this.itemDatas.list[i].name = e.string), this.saveData();
  157. }
  158. }
  159. onEditAbility(t, e) {
  160. t = parseInt(t.string);
  161. isNaN(t) || t < 1 || 10 < t
  162. ? r.default.launch("请输入1~10的数字")
  163. : ((this.itemDatas.list[e].ability = t), this.saveData());
  164. }
  165. onEditGrade(t, e) {
  166. t = parseInt(t.string);
  167. isNaN(t) || t < 1 || 10 < t
  168. ? r.default.launch("请输入1~10的数字")
  169. : ((this.itemDatas.list[e].grade = t), this.saveData());
  170. }
  171. onOutputArchive(t, e) {
  172. var i = this.itemDatas.list,
  173. s = document.createElement("a");
  174. (s.download = "机器人列表.json"), (s.style.display = "none");
  175. i = new Blob([JSON.stringify(i, null, 4)]);
  176. (s.href = URL.createObjectURL(i)), document.body.appendChild(s), s.click(), document.body.removeChild(s);
  177. }
  178. onDeleteArchive(t, e) {
  179. e = parseInt(e);
  180. this.itemDatas.list.splice(e, 1), (this.itemList.numItems = this.itemDatas.list.length), this.saveData();
  181. }
  182. onUploadRobotData(t, i) {
  183. return s(this, void 0, void 0, function* () {
  184. n.default.ViewManager.open(13, {
  185. tipsStr: "是否确定上传机器人数据",
  186. leftBtnText: "确定",
  187. hasCloseBtn: !1,
  188. curState: h.TIPSTATE.SURE_CANCEL,
  189. leftFunc: () =>
  190. s(this, void 0, void 0, function* () {
  191. var t = this.itemDatas.list[i],
  192. e = `${n.default.ConfigManager.gameConf.serverInfos.game}/game/explore/createRobot/${t.ID}/${t.grade}/${t.ability}`,
  193. t = n.default.StringUtil.zipStr1(JSON.stringify(t)),
  194. t = yield n.default.Http.requestWithTokenAsync(
  195. e,
  196. t,
  197. n.default.GameDataMsr.playerInfo.token,
  198. "GET",
  199. "json"
  200. );
  201. 0 === (null == t ? void 0 : t.code)
  202. ? r.default.launch("上传机器人数据成功")
  203. : (Log.error(t), r.default.launch("上传机器人数据失败"));
  204. }),
  205. leftThisObj: this,
  206. rightBtnText: "取消",
  207. rightFunc: () => {},
  208. rightThisObj: this
  209. });
  210. });
  211. }
  212. onLoadArchive(t, e) {
  213. (e = parseInt(e)), (e = this.itemDatas.list[e]);
  214. this.importText(e);
  215. }
  216. onRenderItem(t, e) {
  217. let i = this.itemDatas.list[e],
  218. s = {
  219. edit: t.getChildByName("EditBox").getComponent(cc.EditBox),
  220. rank: t.getChildByName("AbilityBox").getComponent(cc.EditBox),
  221. ability: t.getChildByName("AbilityBox").getComponent(cc.EditBox),
  222. loadBtn: t.getChildByName("加载").getComponent(cc.Button),
  223. delBtn: t.getChildByName("删除").getComponent(cc.Button),
  224. saveBtn: t.getChildByName("保存").getComponent(cc.Button),
  225. uploadBtn: t.getChildByName("上传").getComponent(cc.Button)
  226. };
  227. (s.edit.string = i.name),
  228. (t.getChildByName("IDLab").getComponent(cc.Label).string = "ID:" + i.ID),
  229. (s.loadBtn.clickEvents[0].customEventData =
  230. s.delBtn.clickEvents[0].customEventData =
  231. s.saveBtn.clickEvents[0].customEventData =
  232. s.uploadBtn.clickEvents[0].customEventData =
  233. s.edit.editingDidEnded[0].customEventData =
  234. s.ability.editingDidEnded[0].customEventData =
  235. s.rank.editingDidEnded[0].customEventData =
  236. e + "");
  237. }
  238. };
  239. e([d(cc.EditBox)], t.prototype, "IDBox", void 0),
  240. e([d({type: o.default})], t.prototype, "itemList", void 0),
  241. (t = e([c], t)),
  242. (i.RobotMgrView = t);