GameInit.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * 游戏初始化
  3. */
  4. import DataMgr from "./data/DataMgr";
  5. import { fguiRes } from "./data/Define";
  6. import PlatMgr from "./game/PlatMgr";
  7. import UILoading from "./UI/UILoading";
  8. import UIMain from "./UI/UIMain";
  9. import { xGame } from "./xGame";
  10. /**
  11. * 自定义shader初始化
  12. */
  13. export function InitShader() {
  14. }
  15. //初始化
  16. export function appInit() {
  17. //loading走完后
  18. xGame.context.init(getLoadingResList(), initCallback);
  19. }
  20. function getLoadingResList() {
  21. return [
  22. { url: "fgui/loading_atlas0.png", type: Laya.Loader.IMAGE },
  23. { url: "fgui/loading.obj", type: Laya.Loader.BUFFER }
  24. ]
  25. }
  26. export function getGameResList() {
  27. return [
  28. { url: "asset/fgui/game.obj", type: Laya.Loader.BUFFER },
  29. { url: "asset/fgui/game_atlas0.png", type: Laya.Loader.IMAGE },
  30. { url: "asset/fgui/game_atlas0_1.png", type: Laya.Loader.IMAGE },
  31. { url: "asset/fgui/game_atlas0_2.png", type: Laya.Loader.IMAGE },
  32. { url: "asset/fgui/game_atlas0_3.png", type: Laya.Loader.IMAGE },
  33. { url: "asset/fgui/game_atlas10.png", type: Laya.Loader.IMAGE },
  34. //
  35. // { url: "asset/fgui/game_atlas_kupwv4tc.png", type: Laya.Loader.IMAGE },
  36. //
  37. { url: "asset/fgui/game_atlas_n43d3v3.png", type: Laya.Loader.IMAGE },
  38. { url: "asset/fgui/game_atlas_n43d3v4.png", type: Laya.Loader.IMAGE },
  39. //
  40. { url: "asset/fgui/game_atlas_p4tr427.png", type: Laya.Loader.IMAGE },
  41. { url: "asset/fgui/game_atlas_p4tr42b.png", type: Laya.Loader.IMAGE },
  42. { url: "asset/fgui/game_atlas_p4tr42c.png", type: Laya.Loader.IMAGE },
  43. { url: "asset/fgui/game_atlas_p4tr42e.png", type: Laya.Loader.IMAGE },
  44. // { url: "asset/fgui/game_atlas_p7rrv4r8.png", type: Laya.Loader.IMAGE },
  45. // { url: "asset/fgui/game_atlas_p7rrv4rq.png", type: Laya.Loader.IMAGE },
  46. //
  47. { url: "asset/fgui/game_atlas_rz5r457.jpg", type: Laya.Loader.IMAGE },
  48. //
  49. { url: "asset/fgui/game_atlas_s8sz44t.png", type: Laya.Loader.IMAGE },
  50. { url: "asset/fgui/game_atlas_s8sz44v.png", type: Laya.Loader.IMAGE },
  51. //
  52. { url: "asset/fgui/game_atlas_wehi3uc.jpg", type: Laya.Loader.IMAGE },
  53. //
  54. //加载json
  55. { url: "res/json/npc.json", type: Laya.Loader.JSON },
  56. { url: "res/json/classicCfg.json", type: Laya.Loader.JSON },
  57. { url: "res/json/levelCfg.json", type: Laya.Loader.JSON },
  58. { url: "res/json/placeBallCfg.json", type: Laya.Loader.JSON },
  59. { url: "res/font/arial.ttf", type: Laya.Loader.FONT },
  60. ]
  61. }
  62. function initCallback() {
  63. window["DataMgr"] = DataMgr;
  64. DataMgr.Init();
  65. Moyu.init(getPlat(), this, () => {
  66. DataMgr.isNewDay();
  67. PlatMgr.initConfig();
  68. //
  69. xGame.common.curRankID = Moyu.isWx ? xGame.common.rankID.wxStar : xGame.common.rankID.normalStar;
  70. }, true);
  71. console.log('zh:开始sm init1 start');
  72. xGame.soundMgr.init();
  73. console.log('zh:开始sm init1 end');
  74. //初始化fgui
  75. xGame.uiMgr.init();
  76. xGame.uiMgr.clearTempData();
  77. xGame.uiMgr.bindFUI(fguiRes.loading);
  78. //加载loading界面
  79. xGame.uiMgr.Show(UILoading)
  80. }
  81. export function loadSubRes(callback) {
  82. var tab = ["asset", "res", "spine"];
  83. let subDone = 0;
  84. for (var i = 0; i < tab.length; i++) {
  85. let sub = tab[i];
  86. Moyu.loadSubRes(sub, (pro) => {
  87. callback && callback(pro, false);
  88. }).then(() => {
  89. subDone++;
  90. //console.log(sub + " done")
  91. if (subDone >= tab.length)
  92. callback && callback(1, true);
  93. });
  94. }
  95. }
  96. export function enterGame() {
  97. //常驻公共资源
  98. //初始化json
  99. xGame.cfgMgr.init();
  100. //本地设置
  101. xGame.soundMgr.onSetting(DataMgr.userData.sound);
  102. Moyu.onSetting(DataMgr.userData.sound, DataMgr.userData.vibration);
  103. //UIMain
  104. xGame.uiMgr.Hide(UILoading);
  105. //移除
  106. fgui.UIPackage.removePackage(fguiRes.loading);
  107. //加载初始场景
  108. xGame.uiMgr.bindFUI(fguiRes.game);
  109. //
  110. xGame.uiMgr.Show(UIMain);
  111. //
  112. if (DataMgr.getNewUser()) Moyu.sendDataEvent("logOn", { newPlayerTime: new Date() });
  113. }
  114. function getPlat() {
  115. let cfg: MoyuCfg = new MoyuCfg();
  116. cfg.plat = MoyuPlat.web;
  117. //cfg.myId = 120; 20250627日Q
  118. cfg.myId = 180;
  119. cfg.myKey = '8848a885774230a4';
  120. cfg.version = 0;
  121. if (window.hasOwnProperty("gamebox")) {
  122. cfg.plat = MoyuPlat.f399;
  123. cfg.version = 0;
  124. }
  125. else if (window.hasOwnProperty("ks")) {
  126. cfg.plat = MoyuPlat.ks;
  127. cfg.version = 0;
  128. cfg.ads.ksVideoId = '2300002254_01';
  129. cfg.ads.ksInsertId = '2300002254_02';
  130. }
  131. else if (Laya.Browser.onTTMiniGame) {
  132. cfg.plat = MoyuPlat.tt;
  133. cfg.version = 0;
  134. cfg.ads.ttVideoId = '55lg4hiq6cl1i98a01';
  135. cfg.ads.ttInsertId = '163l1f09abb0fm5l05';
  136. cfg.ads.ttBannerId = "349ld7libg2l5h9a3l";
  137. }
  138. else if (Laya.Browser.onMiniGame) {
  139. cfg.plat = MoyuPlat.wx;
  140. cfg.ads.wxBannerId = 'adunit-fb4acc9e4c4d8c7c';
  141. cfg.ads.wxInsertId = 'adunit-1c0437c20853677c';
  142. cfg.ads.wxVideoId = 'adunit-51758e3d8d649e01';
  143. }
  144. else if (Laya.Browser.onQQMiniGame) {
  145. cfg.plat = MoyuPlat.qq;
  146. }
  147. else if (Laya.Browser.onQGMiniGame) {
  148. cfg.plat = MoyuPlat.op;
  149. cfg.ads.opVideoId = '455502';
  150. cfg.ads.opBannerId = '455507';
  151. //cfg.ads.opNativeId='';
  152. }
  153. else if (Laya.Browser.onVVMiniGame) {
  154. cfg.plat = MoyuPlat.vv;
  155. cfg.version = 0;
  156. cfg.ads.vvVideoId = '405d0513a3964187bfb37aca09da5f45';
  157. cfg.ads.vvInsertId = '72b18a69075c410986ff16e43fb2b0f0';
  158. cfg.ads.vvBannerId = 'fe2d2b92dbc144e086df5150b7d3d3d1';
  159. //cfg.ads.vvNativeId='8c92c739451a4f28b5eb587a0fe9a02d';
  160. }
  161. else if (Laya.Browser.onHWMiniGame) {
  162. cfg.plat = MoyuPlat.hw;
  163. }
  164. else if (window["mz"]) {
  165. cfg.plat = MoyuPlat.mz;
  166. }
  167. else {
  168. let cfg = window['conchConfig'];
  169. if (cfg) {
  170. var os = cfg.getOS();
  171. if (os == "Conch-ios") {
  172. cfg.plat = MoyuPlat.ios;
  173. }
  174. else if (os == "Conch-android") //多android平台需要手动配置
  175. {
  176. // cfg.plat=MoyuPlat.t33;
  177. // cfg.plat=MoyuPlat.mmy;
  178. // cfg.plat=MoyuPlat.xmApk;
  179. }
  180. }
  181. }
  182. return cfg;
  183. }