| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import { AppKernel } from "@scripts/app/AppKernel";
- import { UIViewID } from "@scripts/define/UIDefine";
- import { LOCAL_SIGN } from "@scripts/constants/Localkey";
- import { IGameInfo } from "@scripts/store/pageSlice/data";
- import { localStorageGet } from "@scripts/utils/Helper";
- class LobbyService {
- async launchLobby() {
- const mainStore = AppKernel.stores.mainStore;
- const pageStore = AppKernel.stores.pageStore;
- const firstLaunch = mainStore.firstLaunch;
- if (firstLaunch) {
- // 刚启动未登录
- await Promise.all([
- mainStore.reqGetRoutes(),
- pageStore.reqPageModules(1),
- ])
- }
- const isLogin = mainStore.isLogin;
- if (!isLogin) {
- AppKernel.ui.close(UIViewID.HomeView);
- await AppKernel.ui.open(UIViewID.LoginView);
- return;
- }
- AppKernel.ui.close(UIViewID.LoginView);
- await AppKernel.ui.open(UIViewID.HomeView);
- const gameID = mainStore.gameID;
- if (gameID > 0) {
- this.onGameBack();
- } else {
- this.onAppLaunch();
- }
- }
- async onLoginSuccess() {
- const hallService = AppKernel.services.hallService;
- hallService.connect()
- AppKernel.ui.close(UIViewID.LoginView);
- await AppKernel.ui.open(UIViewID.HomeView);
- AppKernel.events.emit('login:success');
- }
- private async onGameBack() {
- const mainStore = AppKernel.stores.mainStore;
- const gameId = String(mainStore.gameID);
- mainStore.clearGame();
- AppKernel.events.emit('game:exited', { gameId, reason: 'returned-to-lobby' });
- }
- private async onAppLaunch() {
- }
- async openGame(gameID: number) {
- const hallService = AppKernel.services.hallService;
- const mainStore = AppKernel.stores.mainStore;
- mainStore.gameID = gameID
- hallService.sendState();
- 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;
- }
- async exitGame() {
- const hallService = AppKernel.services.hallService;
- const mainStore = AppKernel.stores.mainStore;
- mainStore.clearGame();
- hallService.sendState();
- }
- }
- export const lobbyService = new LobbyService();
|