AppLobby.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { AppKernel } from "@scripts/app/AppKernel";
  2. import { UIViewID } from "@scripts/define/UIDefine";
  3. import { LOCAL_SIGN } from "@scripts/constants/Localkey";
  4. import { localStorageGet } from "@scripts/utils/Helper";
  5. import { CURRENCY_TYPE } from "@scripts/define/Define";
  6. import { IGameInfo } from "@scripts/store/gameStore/data";
  7. class AppLobby {
  8. async launchLobby() {
  9. const mainStore = AppKernel.stores.mainStore;
  10. const firstLaunch = mainStore.firstLaunch;
  11. if (firstLaunch) {
  12. // 自动登录
  13. await mainStore.reqGetRoutes()
  14. }
  15. const isLogin = mainStore.isLogin;
  16. if (!isLogin) {
  17. AppKernel.ui.close(UIViewID.HomeView);
  18. await AppKernel.ui.open(UIViewID.LoginView);
  19. return;
  20. }
  21. const gameStore = AppKernel.stores.gameStore;
  22. const gameID = gameStore.gameID;
  23. if (gameID > 0) {
  24. this.onGameBack();
  25. } else {
  26. this.onLoginSuccess();
  27. }
  28. }
  29. async onLoginSuccess() {
  30. const gameStore = AppKernel.stores.gameStore;
  31. const payStore = AppKernel.stores.payStore;
  32. const hallClient = AppKernel.services.hallClient;
  33. hallClient.connect()
  34. AppKernel.ui.closeAll();
  35. await gameStore.reqAllGames();
  36. await AppKernel.ui.open(UIViewID.HomeView);
  37. await Promise.all([
  38. payStore.reqRechargeConfig(),
  39. ])
  40. AppKernel.events.emit('login:success');
  41. this.onAppLaunch();
  42. }
  43. private async onGameBack() {
  44. AppKernel.ui.closeAll();
  45. await AppKernel.ui.open(UIViewID.HomeView);
  46. const gameStore = AppKernel.stores.gameStore;
  47. const gameId = String(gameStore.gameID);
  48. gameStore.clearGame();
  49. AppKernel.events.emit('game:exited', { gameId, reason: 'returned-to-lobby' });
  50. }
  51. private async onAppLaunch() {
  52. }
  53. async openGame(gameID: number) {
  54. const hallClient = AppKernel.services.hallClient;
  55. const gameStore = AppKernel.stores.gameStore;
  56. gameStore.gameID = gameID
  57. hallClient.sendState();
  58. // const gameInfo = await mainStore.getGameCardInfo(gameID);
  59. // if (!gameInfo) {
  60. // console.error('进入游戏失败');
  61. // return;
  62. // }
  63. // const link = this.parseGameUrl(gameInfo);
  64. // if (!link) {
  65. // console.error('进入游戏失败');
  66. // return;
  67. // }
  68. // mainStore.gameLink = link;
  69. // AppKernel.scenes.goToGame();
  70. }
  71. private parseGameUrl(gameInfo: IGameInfo) {
  72. // const sign = localStorageGet(LOCAL_SIGN);
  73. // let url = `https://testapi.usgamewin.com/game/igt/lunch?softwareid=2001609002`;// gameInfo.link;
  74. // if (gameInfo.level > 0) url += "&level=" + gameInfo.level;
  75. // if (!url) return;
  76. // if (url.indexOf("?") === -1) url = url + "?sign=" + sign;
  77. // else url = url + "&sign=" + sign;
  78. // return url;
  79. return "";
  80. }
  81. async exitGame() {
  82. const hallClient = AppKernel.services.hallClient;
  83. const gameStore = AppKernel.stores.gameStore;
  84. gameStore.clearGame();
  85. hallClient.sendState();
  86. }
  87. async onPaymentFinished() {
  88. AppKernel.events.emit('hall:pay-finished');
  89. const mainStore = AppKernel.stores.mainStore;
  90. const payStore = AppKernel.stores.payStore;
  91. payStore.reqWithdrawBaseInfo();
  92. mainStore.reqUserInfo();
  93. }
  94. }
  95. export const appLobby = new AppLobby();