Optimize initial loading performance
This commit is contained in:
32
src/main.ts
32
src/main.ts
@@ -1,11 +1,8 @@
|
||||
import Phaser from 'phaser';
|
||||
import { effectTracks, musicTracks } from './game/audio/audioAssets';
|
||||
import { soundDirector } from './game/audio/SoundDirector';
|
||||
import { BattleScene } from './game/scenes/BattleScene';
|
||||
import { BootScene } from './game/scenes/BootScene';
|
||||
import { CampScene } from './game/scenes/CampScene';
|
||||
import { EndingScene } from './game/scenes/EndingScene';
|
||||
import { StoryScene } from './game/scenes/StoryScene';
|
||||
import { startLazySceneFromGame } from './game/scenes/lazyScenes';
|
||||
import { TitleScene } from './game/scenes/TitleScene';
|
||||
import './styles/global.css';
|
||||
|
||||
@@ -31,15 +28,23 @@ type HerosDebugApi = {
|
||||
activeScenes: () => string[];
|
||||
battle: () => unknown;
|
||||
camp: () => unknown;
|
||||
goToBattle: () => void;
|
||||
goToCamp: () => void;
|
||||
goToBattle: (battleId?: string) => Promise<void>;
|
||||
goToCamp: () => Promise<void>;
|
||||
forceBattleOutcome: (outcome: 'victory' | 'defeat') => void;
|
||||
scene: (key: string) => Phaser.Scene | undefined;
|
||||
toggleBattleOverlay: () => void;
|
||||
};
|
||||
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const rendererType =
|
||||
searchParams.get('renderer') === 'canvas'
|
||||
? Phaser.CANVAS
|
||||
: searchParams.get('renderer') === 'webgl'
|
||||
? Phaser.WEBGL
|
||||
: Phaser.AUTO;
|
||||
|
||||
const config: Phaser.Types.Core.GameConfig = {
|
||||
type: Phaser.AUTO,
|
||||
type: rendererType,
|
||||
parent: 'game',
|
||||
width: 1280,
|
||||
height: 720,
|
||||
@@ -48,15 +53,16 @@ const config: Phaser.Types.Core.GameConfig = {
|
||||
mode: Phaser.Scale.RESIZE,
|
||||
autoCenter: Phaser.Scale.CENTER_BOTH
|
||||
},
|
||||
scene: [BootScene, TitleScene, StoryScene, BattleScene, CampScene, EndingScene]
|
||||
scene: [BootScene, TitleScene]
|
||||
};
|
||||
|
||||
soundDirector.registerMusicTracks(musicTracks);
|
||||
soundDirector.registerEffectTracks(effectTracks);
|
||||
|
||||
const game = new Phaser.Game(config);
|
||||
const debugEnabled = import.meta.env.DEV || searchParams.has('debug');
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
if (debugEnabled) {
|
||||
window.__HEROS_GAME__ = game;
|
||||
window.__HEROS_DEBUG__ = createDebugApi(game);
|
||||
console.info('[Heros Debug] Use window.__HEROS_DEBUG__.battle() or press F9 in battle.');
|
||||
@@ -72,12 +78,8 @@ function createDebugApi(game: Phaser.Game): HerosDebugApi {
|
||||
activeScenes: () => game.scene.getScenes(true).map((activeScene) => activeScene.scene.key),
|
||||
battle: () => battleScene()?.getDebugState?.() ?? { active: false, reason: 'BattleScene is not active yet.' },
|
||||
camp: () => campScene()?.getDebugState?.() ?? { active: false, reason: 'CampScene is not active yet.' },
|
||||
goToBattle: () => {
|
||||
game.scene.start('BattleScene');
|
||||
},
|
||||
goToCamp: () => {
|
||||
game.scene.start('CampScene');
|
||||
},
|
||||
goToBattle: (battleId) => startLazySceneFromGame(game, 'BattleScene', battleId ? { battleId } : undefined),
|
||||
goToCamp: () => startLazySceneFromGame(game, 'CampScene'),
|
||||
forceBattleOutcome: (outcome) => {
|
||||
battleScene()?.debugForceBattleOutcome?.(outcome);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user