LoadingController.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. o =
  6. (this && this.__awaiter) ||
  7. function (t, n, r, l) {
  8. return new (r = r || Promise)(function (i, e) {
  9. function s(t) {
  10. try {
  11. a(l.next(t));
  12. } catch (t) {
  13. e(t);
  14. }
  15. }
  16. function o(t) {
  17. try {
  18. a(l.throw(t));
  19. } catch (t) {
  20. e(t);
  21. }
  22. }
  23. function a(t) {
  24. var e;
  25. t.done
  26. ? i(t.value)
  27. : ((e = t.value) instanceof r
  28. ? e
  29. : new r(function (t) {
  30. t(e);
  31. })
  32. ).then(s, o);
  33. }
  34. a((l = l.apply(t, n || [])).next());
  35. });
  36. };
  37. Object.defineProperty(i, "__esModule", {value: !0}), (i.LoadingConst = void 0);
  38. const a = t("App"),
  39. n = t("BaseController"),
  40. r = t("HotUpdate"),
  41. l = t("ViewConst"),
  42. h = (t("LayerManager"), t("SceneConst"));
  43. ((t = s = i.LoadingConst || (i.LoadingConst = {}))[(t.SetProgress = 0)] = "SetProgress"),
  44. (t[(t.AddProgressCompleteCB = 1)] = "AddProgressCompleteCB"),
  45. (t[(t.ProgressComplete = 2)] = "ProgressComplete"),
  46. (t[(t.SetIsShowBillBoard = 3)] = "SetIsShowBillBoard"),
  47. (i.default = class extends n.default {
  48. constructor() {
  49. super(),
  50. (this.completeCb = null),
  51. (this.completeTaget = null),
  52. (this.hotUPdate = null),
  53. a.default.DebugUtils.isOpen(!0),
  54. (this.loadProgress = {
  55. gameRes: {cur: 0, rate: 20},
  56. gameZipRes: {cur: 0, rate: 20},
  57. configAndLoadgame: {cur: 0, rate: 10},
  58. preloadRes: {cur: 0, rate: 20},
  59. syncData: {cur: 0, rate: 10},
  60. allCnt: {cur: 0, rate: 0}
  61. });
  62. let t = 0;
  63. for (const e in this.loadProgress) t += this.loadProgress[e].rate;
  64. (this.loadProgress.allCnt.rate = t),
  65. a.default.ViewManager.register(0, {prefabName: "LoadingView", zIndex: 0, controller: this}),
  66. a.default.ViewManager.register(6, {
  67. prefabName: "DebugUI",
  68. zIndex: 250,
  69. controller: this,
  70. isNotShowLoad: !0
  71. }),
  72. a.default.ViewManager.register(13, {prefabName: "TipView", zIndex: 100, controller: this}),
  73. a.default.ViewManager.register(5, {prefabName: "ArchiveonMgrView", zIndex: 100, controller: this}),
  74. a.default.ViewManager.register(14, {
  75. prefabName: "TipView",
  76. zIndex: 250,
  77. isNotShowLoad: !0,
  78. controller: this
  79. }),
  80. this.registerFunc(s.SetProgress, this.setProgress, this),
  81. this.registerFunc(s.AddProgressCompleteCB, this.setProgress, this),
  82. this.registerFunc(s.ProgressComplete, this.onProgressComplete, this),
  83. a.default.ViewManager.open(0);
  84. }
  85. onProgressComplete() {
  86. this.completeCb &&
  87. (this.completeCb.call(this.completeTaget), (this.completeTaget = this.completeCb = null));
  88. }
  89. onGameStart() {
  90. a.default.DebugUtils.stop("加载时间", "开始进入场景"), a.default.SceneManager.runScene(h.SceneTag.GAME);
  91. }
  92. onAddProgressCompleteCB(t, e) {
  93. (this.completeCb = t), (this.completeTaget = e);
  94. }
  95. setProgress(t, e) {
  96. if (((this.loadProgress[e].cur = t), this.loadingView)) {
  97. let t = 0;
  98. for (var i in this.loadProgress) t += this.loadProgress[i].cur * this.loadProgress[i].rate;
  99. this.loadingView.onProgress(t / this.loadProgress.allCnt.rate);
  100. }
  101. }
  102. onLoadView(t) {
  103. return o(this, void 0, void 0, function* () {
  104. 0 === t.viewId && this.loadGame(t);
  105. });
  106. }
  107. onOpenView(t) {}
  108. onCloseView(t) {
  109. return o(this, void 0, void 0, function* () {
  110. t.viewId === l.ViewConst.BillboardView && this.setProgress(1, "billbord");
  111. });
  112. }
  113. loadGame(t) {
  114. return o(this, void 0, void 0, function* () {
  115. (t = t || a.default.ViewManager.getView(0)),
  116. a.default.DebugUtils.start("加载时间"),
  117. this.onAddProgressCompleteCB(this.onGameStart, this),
  118. (this.loadingView = t),
  119. (this.hotUPdate = cc.director.getScene().getComponentInChildren(r.default)),
  120. this.loadingView.checkHot(),
  121. yield this.hotUPdate.checkUpdate((t, e, i) => {
  122. this.loadingView.onHotProgress(t, e, i);
  123. }),
  124. (a.default.GameDataMsr.tempData.isCheckUpdate = !0),
  125. Log.trace("开始加载本地存档数据!"),
  126. a.default.GameDataMsr.init(),
  127. cc.log("开始加载配置文件"),
  128. yield a.default.ConfigManager.loadAllConfig((t, e) => {
  129. this.setProgress(t / e, "configAndLoadgame");
  130. }, this),
  131. Log.trace("初始化平台类!"),
  132. a.default.Platform.init(),
  133. Log.trace("开始跟服务器同步存档数据!"),
  134. a.default.DebugUtils.start("同步数据"),
  135. yield a.default.Platform.syncData().then(() => {
  136. this.setProgress(1, "syncData");
  137. }),
  138. a.default.DebugUtils.stop("同步数据"),
  139. a.default.SaveManage.init(),
  140. a.default.DebugUtils.stop("加载时间", "开始加载压缩包");
  141. let i = yield a.default.Platform.loadZipFile((t, e) => {
  142. this.setProgress(t / e, "gameZipRes");
  143. });
  144. a.default.DebugUtils.stop("加载时间", "加载压缩包完毕"),
  145. a.default.SceneManager.preLoadScene(
  146. h.SceneTag.GAME,
  147. (t, e) => {
  148. this.setProgress(t / e, "gameRes"), i || this.setProgress(t / e, "gameZipRes");
  149. },
  150. null
  151. ),
  152. Log.trace("开始检查是否需要更新每日数据!"),
  153. a.default.GameDataMsr.loadData(),
  154. a.default.SaveManage.checkIsNeedUpdateData(),
  155. this.setProgress(1, "preloadRes"),
  156. a.default.SaveManage.load(a.default.SoundManager.saveKey);
  157. });
  158. }
  159. });