| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { AppKernel } from "@scripts/app/AppKernel";
- import { UIViewID } from "@scripts/define/UIDefine";
- import { LOCAL_SIGN } from "@scripts/constants/Localkey";
- import { localStorageGet, localStorageRemove } from "@scripts/utils/Helper";
- import { CURRENCY_TYPE } from "@scripts/define/Define";
- import { IGameInfo } from "@scripts/store/gameStore/data";
- class AppLobby {
- async launchLobby() {
- const mainStore = AppKernel.stores.mainStore;
- const firstLaunch = mainStore.firstLaunch;
- if (firstLaunch) {
- AppKernel.sound.playBgm();
- // 自动登录
- await mainStore.reqGetRoutes()
- }
- const isLogin = mainStore.isLogin;
- if (!isLogin) {
- AppKernel.ui.close(UIViewID.HomeView);
- await AppKernel.ui.open(UIViewID.LoginView);
- return;
- }
- const gameStore = AppKernel.stores.gameStore;
- const gameID = gameStore.gameID;
- if (gameID > 0) {
- await this.onGameBack();
- } else {
- await this.onLoginSuccess();
- }
- }
- async onLoginSuccess() {
- const gameStore = AppKernel.stores.gameStore;
- const payStore = AppKernel.stores.payStore;
- const hallClient = AppKernel.services.hallClient;
- hallClient.connect();
- await Promise.all([
- gameStore.reqAllGames(),
- payStore.reqRechargeConfig(),
- payStore.reqFirstPackVisible(),
- ])
- await AppKernel.ui.closeAll();
- AppKernel.ui.open(UIViewID.HomeView);
- AppKernel.events.emit('login:success');
- this.onAppLaunch();
- }
- private async onGameBack() {
- await AppKernel.ui.open(UIViewID.HomeView);
- AppKernel.ui.closeAll();
- const gameStore = AppKernel.stores.gameStore;
- const gameId = String(gameStore.gameID);
- gameStore.clearGame();
- AppKernel.events.emit('game:exited', { gameId, reason: 'returned-to-lobby' });
- }
- private async onAppLaunch() {
- }
- async openGame(game: IGameInfo) {
- AppKernel.ui.loading(true);
- const hallClient = AppKernel.services.hallClient;
- const mainStore = AppKernel.stores.mainStore;
- const gameStore = AppKernel.stores.gameStore;
- gameStore.gameID = game.gameID;
- hallClient.sendState();
- const url = await gameStore.reqLaunchGame(game.gameCode, mainStore.currencyKind);
- AppKernel.ui.loading(false);
- console.log('game url: ', url);
- // const gameInfo = await mainStore.getGameCardInfo(gameID);
- // if (!gameInfo) {
- // console.error('进入游戏失败');
- // return;
- // }
- // const link = this.parseGameUrl(gameInfo);
- // if (!link) {
- // console.error('进入游戏失败');
- // return;
- // }
- // mainStore.gameLink = link;
- // AppKernel.scenes.goToGame();
- }
- private parseGameUrl(gameInfo: IGameInfo) {
- // const sign = localStorageGet(LOCAL_SIGN);
- // let url = `https://testapi.usgamewin.com/game/igt/lunch?softwareid=2001609002`;// gameInfo.link;
- // if (gameInfo.level > 0) url += "&level=" + gameInfo.level;
- // if (!url) return;
- // if (url.indexOf("?") === -1) url = url + "?sign=" + sign;
- // else url = url + "&sign=" + sign;
- // return url;
- return "";
- }
- async exitGame() {
- const hallClient = AppKernel.services.hallClient;
- const gameStore = AppKernel.stores.gameStore;
- gameStore.clearGame();
- hallClient.sendState();
- }
- async onPaymentFinished() {
- AppKernel.events.emit('hall:pay-finished');
- const mainStore = AppKernel.stores.mainStore;
- const payStore = AppKernel.stores.payStore;
- payStore.reqWithdrawBaseInfo();
- mainStore.reqUserInfo();
- }
- async logOut() {
- AppKernel.ui.loading(true);
- const mainStore = AppKernel.stores.mainStore;
- if (!await mainStore.reqLogout()) {
- console.error('log out failed!!!');
- AppKernel.ui.loading(false);
- return;
- }
- localStorageRemove(LOCAL_SIGN);
- AppKernel.fb?.logOut();
- await AppKernel.stores.onUserLogout();
- await AppKernel.ui.open(UIViewID.LoginView);
- AppKernel.ui.loading(false);
- }
- }
- export const appLobby = new AppLobby();
|