ArchiveonMgrView.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  6. (this && this.__decorate) ||
  7. function (t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. },
  17. a =
  18. (this && this.__awaiter) ||
  19. function (t, n, r, l) {
  20. return new (r = r || Promise)(function (i, e) {
  21. function s(t) {
  22. try {
  23. a(l.next(t));
  24. } catch (t) {
  25. e(t);
  26. }
  27. }
  28. function o(t) {
  29. try {
  30. a(l.throw(t));
  31. } catch (t) {
  32. e(t);
  33. }
  34. }
  35. function a(t) {
  36. var e;
  37. t.done
  38. ? i(t.value)
  39. : ((e = t.value) instanceof r
  40. ? e
  41. : new r(function (t) {
  42. t(e);
  43. })
  44. ).then(s, o);
  45. }
  46. a((l = l.apply(t, n || [])).next());
  47. });
  48. };
  49. Object.defineProperty(i, "__esModule", {value: !0}), (i.ArchiveonMgrView = void 0);
  50. const n = t("App"),
  51. o = t("List"),
  52. r = t("BaseView"),
  53. l = t("Toast"),
  54. h = (t("ViewConst"), t("GameDataMsr")),
  55. c = t("TipView"),
  56. {ccclass: d, property: u} = cc._decorator;
  57. let p = null,
  58. f = (s = class extends r.default {
  59. constructor() {
  60. super(...arguments), (this.itemList = null), (this.itemDatas = null), (this.items = []);
  61. }
  62. initUI() {
  63. super.initUI(),
  64. (this.itemDatas = s.getArchiveonData()),
  65. (this.itemList.numItems = this.itemDatas.list.length);
  66. }
  67. static getArchiveonData() {
  68. if (!p) {
  69. var t = cc.sys.localStorage.getItem("ArchiveonCache");
  70. if (t)
  71. try {
  72. p = JSON.parse(t);
  73. } catch (t) {
  74. p = {cur: "", list: []};
  75. }
  76. else p = {cur: "", list: []};
  77. }
  78. return p;
  79. }
  80. saveData() {
  81. cc.sys.localStorage.setItem("ArchiveonCache", JSON.stringify(this.itemDatas));
  82. }
  83. loadRemote(o) {
  84. return a(this, void 0, void 0, function* () {
  85. const s = yield n.default.Http.requestAsync(
  86. "https://wxclient.gzqidong.cn/MergeElves/archive/assets/archive/r_cfg.txt?" + Date.now(),
  87. {},
  88. "GET"
  89. );
  90. Log.trace("result:", s),
  91. cc.assetManager.downloader.bundleVers
  92. ? (cc.assetManager.downloader.bundleVers.archive = s)
  93. : (cc.assetManager.downloader.bundleVers = {archive: s});
  94. var t = o.target.getComponentInChildren(cc.EditBox).string || "normal";
  95. for (const o of yield n.default.ResManager.loadDirInBundle(
  96. "https://wxclient.gzqidong.cn/MergeElves/archive/assets/archive",
  97. t,
  98. cc.JsonAsset
  99. )) {
  100. const s = o.json;
  101. let t = !1,
  102. e = this.itemDatas.list.length,
  103. i = 0;
  104. for (; i < e; i++)
  105. if (this.itemDatas.list[i].name == s.name) {
  106. t = !0;
  107. break;
  108. }
  109. t
  110. ? (this.itemDatas.list[i] = s)
  111. : s.name
  112. ? this.itemDatas.list.push(s)
  113. : this.itemDatas.list.push({name: new Date().Format("远程-0(MM-dd hh:mm:ss)"), data: s});
  114. }
  115. l.default.launch("导入完成!"), (this.itemList.numItems = this.itemDatas.list.length), this.saveData();
  116. });
  117. }
  118. addNewArchive(t) {
  119. let i = t.target.getComponentInChildren(cc.EditBox);
  120. try {
  121. let e;
  122. (e = i.string.includes("{") ? JSON.parse(i.string) : JSON.parse(n.default.StringUtil.unzip(i.string)))
  123. .name || (e = {name: new Date().Format("存档(MM-dd hh:mm:ss)"), data: e});
  124. var s = this.itemDatas.list.length;
  125. for (let t = 0; t < s; t++)
  126. if (this.itemDatas.list[t].name == e.name)
  127. return void n.default.ViewManager.open(14, {
  128. tipsStr: "已有相同名字的存档,是否覆盖旧存档!!!",
  129. leftBtnText: "覆盖",
  130. hasCloseBtn: !1,
  131. curState: c.TIPSTATE.SURE_CANCEL,
  132. leftFunc: () => {
  133. (this.itemDatas.list[t] = e), l.default.launch("导入存档成功,覆盖了旧的存档!");
  134. },
  135. leftThisObj: this,
  136. rightBtnText: "新增",
  137. rightFunc: () => {
  138. this.itemDatas.list.push(e),
  139. (e.name += "(new)"),
  140. (this.itemList.numItems = this.itemDatas.list.length),
  141. l.default.launch("导入了存档:" + e.name);
  142. },
  143. rightThisObj: this
  144. });
  145. this.itemDatas.list.push(e), (this.itemList.numItems = this.itemDatas.list.length), this.saveData();
  146. } catch (t) {
  147. l.default.launch("导入失败!"), Log.error(t);
  148. }
  149. }
  150. addCurArchive(t) {
  151. var i = t.target.getComponentInChildren(cc.EditBox);
  152. try {
  153. let e = n.default.SaveManage.getAllAutoSaveData();
  154. if (i.string) {
  155. var s = this.itemDatas.list.length;
  156. for (let t = 0; t < s; t++)
  157. if (this.itemDatas.list[t].name == i.string)
  158. return void n.default.ViewManager.open(14, {
  159. tipsStr: "已有相同名字的存档,是否覆盖旧存档!!!",
  160. leftBtnText: "覆盖",
  161. hasCloseBtn: !1,
  162. curState: c.TIPSTATE.SURE_CANCEL,
  163. leftFunc: () => {
  164. (this.itemDatas.list[t].data = e), this.saveData(), l.default.launch("存入成功!");
  165. },
  166. leftThisObj: this,
  167. rightBtnText: "取消",
  168. rightFunc: () => {},
  169. rightThisObj: this
  170. });
  171. var o = i.string;
  172. } else o = new Date().Format("存档(MM-dd hh:mm:ss)");
  173. this.itemDatas.list.push({name: o, data: JSON.parse(e)}),
  174. (this.itemList.numItems = this.itemDatas.list.length),
  175. this.saveData();
  176. } catch (t) {
  177. l.default.launch("导入失败!"), Log.error(t);
  178. }
  179. }
  180. importText(a) {
  181. try {
  182. let t = "string" == typeof a.data ? JSON.parse(a.data) : a.data,
  183. e = Object.keys(t),
  184. i = {};
  185. for (const a of e) i[a.replace(/[\d]{8}/, "")] = t[a];
  186. let s = (t = i)[h.GameDataSaveKey.PLAYER_INFO],
  187. o = n.default.GameDataMsr.playerInfo;
  188. (s.saveTime = n.default.DateUtils.Now()),
  189. (s.id = o.id),
  190. (s.account = o.account),
  191. (s.nickName = o.nickName),
  192. n.default.SaveManage.syncByData(t),
  193. (n.default.GameDataMsr.playerInfo.token = null),
  194. n.default.SaveManage.clearAllItem(),
  195. n.default.ViewManager.open(14, {
  196. tipsStr: "导入存档成功",
  197. hasCloseBtn: !1,
  198. curState: c.TIPSTATE.SURE,
  199. leftFunc: () => {
  200. n.default.Platform.resetGame();
  201. },
  202. leftThisObj: this
  203. });
  204. } catch (t) {
  205. n.default.ViewManager.open(14, {
  206. tipsStr: "导入存档出错",
  207. curState: c.TIPSTATE.NO_SURE,
  208. hasCloseBtn: !0
  209. });
  210. }
  211. }
  212. onEditArchiveName(e, i) {
  213. if (this.itemDatas.list[i].name != e.string) {
  214. var s = this.itemDatas.list.length;
  215. for (let t = 0; t < s; t++)
  216. if (this.itemDatas.list[t].name == e.string)
  217. return (
  218. l.default.launch("修改失败,存档名不允许重复"), void (e.string = this.itemDatas.list[i].name)
  219. );
  220. (this.itemDatas.list[i].name = e.string), this.saveData();
  221. }
  222. }
  223. onOutputArchive(t, e) {
  224. var i,
  225. s = parseInt(e),
  226. e = this.itemDatas.list[s];
  227. cc.sys.platform !== cc.sys.WECHAT_GAME
  228. ? (((i = document.createElement("a")).download = e.name + ".json"),
  229. (i.style.display = "none"),
  230. (s = new Blob([JSON.stringify(e, null, 4)])),
  231. (i.href = URL.createObjectURL(s)),
  232. document.body.appendChild(i),
  233. i.click(),
  234. document.body.removeChild(i))
  235. : ((i = ""),
  236. (i = "string" == typeof e.data ? e.data : n.default.StringUtil.zipStr(JSON.stringify(e.data))),
  237. wx.setClipboardData({data: i, success(t) {}}));
  238. }
  239. onDeleteArchive(t, e) {
  240. e = parseInt(e);
  241. this.itemDatas.list.splice(e, 1), (this.itemList.numItems = this.itemDatas.list.length), this.saveData();
  242. }
  243. onLoadArchive(t, e) {
  244. (e = parseInt(e)), (e = this.itemDatas.list[e]);
  245. this.importText(e);
  246. }
  247. onRenderItem(t, e) {
  248. let i = this.itemDatas.list[e],
  249. s = t.getChildByName("btns"),
  250. o = {
  251. edit: t.getChildByName("EditBox").getComponent(cc.EditBox),
  252. loadBtn: s.getChildByName("加载").getComponent(cc.Button),
  253. delBtn: s.getChildByName("删除").getComponent(cc.Button),
  254. outputBtn: s.getChildByName("导出").getComponent(cc.Button),
  255. visistBtn: s.getChildByName("访问").getComponent(cc.Button)
  256. };
  257. (o.edit.string = i.name),
  258. (o.loadBtn.clickEvents[0].customEventData =
  259. o.delBtn.clickEvents[0].customEventData =
  260. o.visistBtn.clickEvents[0].customEventData =
  261. o.outputBtn.clickEvents[0].customEventData =
  262. o.edit.editingDidEnded[0].customEventData =
  263. e + "");
  264. }
  265. });
  266. e([u({type: o.default})], f.prototype, "itemList", void 0), (s = e([d], f)), (i.ArchiveonMgrView = s);