-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.ts
38 lines (35 loc) · 981 Bytes
/
init.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
baseInit$,
initDeferred$,
initQspApi,
initialBaseUrl$,
onGameEnd$,
registerDefaultThemes,
runGame,
windowManager$,
} from '@qspider/game-state';
import { windowManager } from '@qspider/window-manager';
import { runConfig } from './config-runner';
declare const APP_MODE: string;
export async function init(): Promise<void> {
document.body.classList.add(`mode-${APP_MODE}`);
const url = new URL(window.location.href);
url.search = '';
url.hash = '';
let baseUrl = url.toString();
if (!baseUrl.endsWith('/')) {
baseUrl = `${baseUrl}/`;
}
initialBaseUrl$.set(baseUrl);
windowManager$.set(windowManager);
onGameEnd$.set(() => {
windowManager.closeWindow();
});
const configUrl = new URL('game/game.cfg', baseUrl);
const game = await runConfig(configUrl.toString());
initDeferred$.value.resolve();
await initQspApi();
await registerDefaultThemes(initialBaseUrl$.value);
await runGame(game);
baseInit$.set(true);
}