Optimize initial loading performance

This commit is contained in:
2026-06-27 07:49:38 +09:00
parent 88207c3b6f
commit b74332973b
14 changed files with 552 additions and 533 deletions

View File

@@ -1,85 +1,24 @@
import Phaser from 'phaser';
import { soundDirector } from '../audio/SoundDirector';
import { firstBattleVictoryPages } from '../data/scenario';
import {
eighthBattleScenario,
eighteenthBattleScenario,
eleventhBattleScenario,
fiftiethBattleScenario,
fiftyFirstBattleScenario,
fiftySecondBattleScenario,
fiftyThirdBattleScenario,
fiftyFourthBattleScenario,
fiftyFifthBattleScenario,
fiftySixthBattleScenario,
fiftySeventhBattleScenario,
fiftyEighthBattleScenario,
fiftyNinthBattleScenario,
sixtiethBattleScenario,
sixtyFirstBattleScenario,
sixtySecondBattleScenario,
sixtyThirdBattleScenario,
sixtyFourthBattleScenario,
sixtyFifthBattleScenario,
sixtySixthBattleScenario,
fortiethBattleScenario,
fortyFirstBattleScenario,
fortySecondBattleScenario,
fortyThirdBattleScenario,
fortyFourthBattleScenario,
fortyFifthBattleScenario,
fortyEighthBattleScenario,
fortyNinthBattleScenario,
fortySixthBattleScenario,
fortySeventhBattleScenario,
fifthBattleScenario,
fifteenthBattleScenario,
fourteenthBattleScenario,
fourthBattleScenario,
ninthBattleScenario,
nineteenthBattleScenario,
secondBattleScenario,
seventhBattleScenario,
sixthBattleScenario,
sixteenthBattleScenario,
seventeenthBattleScenario,
tenthBattleScenario,
thirteenthBattleScenario,
thirtyEighthBattleScenario,
thirtyFifthBattleScenario,
thirtyFourthBattleScenario,
thirtyFirstBattleScenario,
thirtyNinthBattleScenario,
thirtySecondBattleScenario,
thirtyThirdBattleScenario,
thirtySixthBattleScenario,
thirtySeventhBattleScenario,
thirtiethBattleScenario,
twentyEighthBattleScenario,
twentyFirstBattleScenario,
twentySecondBattleScenario,
twentyThirdBattleScenario,
twentyFifthBattleScenario,
twentyFourthBattleScenario,
twentyNinthBattleScenario,
twentySixthBattleScenario,
twentySeventhBattleScenario,
twentiethBattleScenario,
twelfthBattleScenario,
thirdBattleScenario
} from '../data/battles';
import { battleIdForCampaignStep, isCampCampaignStep } from '../state/campaignRouting';
import { hasCampaignSave, loadCampaignState, startNewCampaign } from '../state/campaignState';
import { palette } from '../ui/palette';
import { startLazyScene } from './lazyScenes';
export class TitleScene extends Phaser.Scene {
private focusedButton?: Phaser.GameObjects.Text;
private settingsPanel?: Phaser.GameObjects.Container;
private navigating = false;
constructor() {
super('TitleScene');
}
create() {
this.focusedButton = undefined;
this.settingsPanel = undefined;
this.navigating = false;
const { width, height } = this.scale;
this.drawBackground(width, height);
this.drawAtmosphere(width, height);
@@ -356,431 +295,54 @@ export class TitleScene extends Phaser.Scene {
soundDirector.resume();
soundDirector.playSelect();
startNewCampaign();
this.scene.start('StoryScene');
void this.navigateTo('StoryScene');
}
private continueGame() {
soundDirector.start();
soundDirector.resume();
soundDirector.playSelect();
void this.continueGameAsync();
}
private async continueGameAsync() {
const campaign = loadCampaignState();
if (campaign.step === 'ending-complete') {
this.scene.start('EndingScene');
await this.navigateTo('EndingScene');
return;
}
if (
campaign.step === 'first-camp' ||
campaign.step === 'second-camp' ||
campaign.step === 'third-camp' ||
campaign.step === 'fourth-camp' ||
campaign.step === 'fifth-camp' ||
campaign.step === 'sixth-camp' ||
campaign.step === 'seventh-camp' ||
campaign.step === 'eighth-camp' ||
campaign.step === 'ninth-camp' ||
campaign.step === 'tenth-camp' ||
campaign.step === 'eleventh-camp' ||
campaign.step === 'twelfth-camp' ||
campaign.step === 'thirteenth-camp' ||
campaign.step === 'fourteenth-camp' ||
campaign.step === 'fifteenth-camp' ||
campaign.step === 'sixteenth-camp' ||
campaign.step === 'seventeenth-camp' ||
campaign.step === 'eighteenth-camp' ||
campaign.step === 'nineteenth-camp' ||
campaign.step === 'twentieth-camp' ||
campaign.step === 'twenty-first-camp' ||
campaign.step === 'twenty-second-camp' ||
campaign.step === 'twenty-third-camp' ||
campaign.step === 'twenty-fourth-camp' ||
campaign.step === 'twenty-fifth-camp' ||
campaign.step === 'twenty-sixth-camp' ||
campaign.step === 'twenty-seventh-camp' ||
campaign.step === 'twenty-eighth-camp' ||
campaign.step === 'twenty-ninth-camp' ||
campaign.step === 'thirtieth-camp' ||
campaign.step === 'thirty-first-camp' ||
campaign.step === 'thirty-second-camp' ||
campaign.step === 'thirty-third-camp' ||
campaign.step === 'thirty-fourth-camp' ||
campaign.step === 'thirty-fifth-camp' ||
campaign.step === 'thirty-sixth-camp' ||
campaign.step === 'thirty-seventh-camp' ||
campaign.step === 'thirty-eighth-camp' ||
campaign.step === 'thirty-ninth-camp' ||
campaign.step === 'fortieth-camp' ||
campaign.step === 'forty-first-camp' ||
campaign.step === 'forty-second-camp' ||
campaign.step === 'forty-third-camp' ||
campaign.step === 'forty-fourth-camp' ||
campaign.step === 'forty-fifth-camp' ||
campaign.step === 'forty-sixth-camp' ||
campaign.step === 'forty-seventh-camp' ||
campaign.step === 'forty-eighth-camp' ||
campaign.step === 'forty-ninth-camp' ||
campaign.step === 'fiftieth-camp' ||
campaign.step === 'fifty-first-camp' ||
campaign.step === 'fifty-second-camp' ||
campaign.step === 'fifty-third-camp' ||
campaign.step === 'fifty-fourth-camp' ||
campaign.step === 'fifty-fifth-camp' ||
campaign.step === 'fifty-sixth-camp' ||
campaign.step === 'fifty-seventh-camp' ||
campaign.step === 'fifty-eighth-camp' ||
campaign.step === 'fifty-ninth-camp' ||
campaign.step === 'sixtieth-camp' ||
campaign.step === 'sixty-first-camp' ||
campaign.step === 'sixty-second-camp' ||
campaign.step === 'sixty-third-camp' ||
campaign.step === 'sixty-fourth-camp' ||
campaign.step === 'sixty-fifth-camp' ||
campaign.step === 'sixty-sixth-camp' ||
campaign.step === 'hanzhong-king-camp' ||
campaign.step === 'shu-han-foundation-camp' ||
campaign.step === 'baidi-entrustment-camp' ||
campaign.step === 'northern-campaign-prep-camp'
) {
this.scene.start('CampScene');
if (isCampCampaignStep(campaign.step)) {
await this.navigateTo('CampScene');
return;
}
if (campaign.step === 'first-battle') {
this.scene.start('BattleScene');
return;
}
if (campaign.step === 'second-battle') {
this.scene.start('BattleScene', { battleId: secondBattleScenario.id });
return;
}
if (campaign.step === 'third-battle') {
this.scene.start('BattleScene', { battleId: thirdBattleScenario.id });
return;
}
if (campaign.step === 'fourth-battle') {
this.scene.start('BattleScene', { battleId: fourthBattleScenario.id });
return;
}
if (campaign.step === 'fifth-battle') {
this.scene.start('BattleScene', { battleId: fifthBattleScenario.id });
return;
}
if (campaign.step === 'sixth-battle') {
this.scene.start('BattleScene', { battleId: sixthBattleScenario.id });
return;
}
if (campaign.step === 'seventh-battle') {
this.scene.start('BattleScene', { battleId: seventhBattleScenario.id });
return;
}
if (campaign.step === 'eighth-battle') {
this.scene.start('BattleScene', { battleId: eighthBattleScenario.id });
return;
}
if (campaign.step === 'ninth-battle') {
this.scene.start('BattleScene', { battleId: ninthBattleScenario.id });
return;
}
if (campaign.step === 'tenth-battle') {
this.scene.start('BattleScene', { battleId: tenthBattleScenario.id });
return;
}
if (campaign.step === 'eleventh-battle') {
this.scene.start('BattleScene', { battleId: eleventhBattleScenario.id });
return;
}
if (campaign.step === 'twelfth-battle') {
this.scene.start('BattleScene', { battleId: twelfthBattleScenario.id });
return;
}
if (campaign.step === 'thirteenth-battle') {
this.scene.start('BattleScene', { battleId: thirteenthBattleScenario.id });
return;
}
if (campaign.step === 'fourteenth-battle') {
this.scene.start('BattleScene', { battleId: fourteenthBattleScenario.id });
return;
}
if (campaign.step === 'fifteenth-battle') {
this.scene.start('BattleScene', { battleId: fifteenthBattleScenario.id });
return;
}
if (campaign.step === 'sixteenth-battle') {
this.scene.start('BattleScene', { battleId: sixteenthBattleScenario.id });
return;
}
if (campaign.step === 'seventeenth-battle') {
this.scene.start('BattleScene', { battleId: seventeenthBattleScenario.id });
return;
}
if (campaign.step === 'eighteenth-battle') {
this.scene.start('BattleScene', { battleId: eighteenthBattleScenario.id });
return;
}
if (campaign.step === 'nineteenth-battle') {
this.scene.start('BattleScene', { battleId: nineteenthBattleScenario.id });
return;
}
if (campaign.step === 'twentieth-battle') {
this.scene.start('BattleScene', { battleId: twentiethBattleScenario.id });
return;
}
if (campaign.step === 'twenty-first-battle') {
this.scene.start('BattleScene', { battleId: twentyFirstBattleScenario.id });
return;
}
if (campaign.step === 'twenty-second-battle') {
this.scene.start('BattleScene', { battleId: twentySecondBattleScenario.id });
return;
}
if (campaign.step === 'twenty-third-battle') {
this.scene.start('BattleScene', { battleId: twentyThirdBattleScenario.id });
return;
}
if (campaign.step === 'twenty-fourth-battle') {
this.scene.start('BattleScene', { battleId: twentyFourthBattleScenario.id });
return;
}
if (campaign.step === 'twenty-fifth-battle') {
this.scene.start('BattleScene', { battleId: twentyFifthBattleScenario.id });
return;
}
if (campaign.step === 'twenty-sixth-battle') {
this.scene.start('BattleScene', { battleId: twentySixthBattleScenario.id });
return;
}
if (campaign.step === 'twenty-seventh-battle') {
this.scene.start('BattleScene', { battleId: twentySeventhBattleScenario.id });
return;
}
if (campaign.step === 'twenty-eighth-battle') {
this.scene.start('BattleScene', { battleId: twentyEighthBattleScenario.id });
return;
}
if (campaign.step === 'twenty-ninth-battle') {
this.scene.start('BattleScene', { battleId: twentyNinthBattleScenario.id });
return;
}
if (campaign.step === 'thirtieth-battle') {
this.scene.start('BattleScene', { battleId: thirtiethBattleScenario.id });
return;
}
if (campaign.step === 'thirty-first-battle') {
this.scene.start('BattleScene', { battleId: thirtyFirstBattleScenario.id });
return;
}
if (campaign.step === 'thirty-second-battle') {
this.scene.start('BattleScene', { battleId: thirtySecondBattleScenario.id });
return;
}
if (campaign.step === 'thirty-third-battle') {
this.scene.start('BattleScene', { battleId: thirtyThirdBattleScenario.id });
return;
}
if (campaign.step === 'thirty-fourth-battle') {
this.scene.start('BattleScene', { battleId: thirtyFourthBattleScenario.id });
return;
}
if (campaign.step === 'thirty-fifth-battle') {
this.scene.start('BattleScene', { battleId: thirtyFifthBattleScenario.id });
return;
}
if (campaign.step === 'thirty-sixth-battle') {
this.scene.start('BattleScene', { battleId: thirtySixthBattleScenario.id });
return;
}
if (campaign.step === 'thirty-seventh-battle') {
this.scene.start('BattleScene', { battleId: thirtySeventhBattleScenario.id });
return;
}
if (campaign.step === 'thirty-eighth-battle') {
this.scene.start('BattleScene', { battleId: thirtyEighthBattleScenario.id });
return;
}
if (campaign.step === 'thirty-ninth-battle') {
this.scene.start('BattleScene', { battleId: thirtyNinthBattleScenario.id });
return;
}
if (campaign.step === 'fortieth-battle') {
this.scene.start('BattleScene', { battleId: fortiethBattleScenario.id });
return;
}
if (campaign.step === 'forty-first-battle') {
this.scene.start('BattleScene', { battleId: fortyFirstBattleScenario.id });
return;
}
if (campaign.step === 'forty-second-battle') {
this.scene.start('BattleScene', { battleId: fortySecondBattleScenario.id });
return;
}
if (campaign.step === 'forty-third-battle') {
this.scene.start('BattleScene', { battleId: fortyThirdBattleScenario.id });
return;
}
if (campaign.step === 'forty-fourth-battle') {
this.scene.start('BattleScene', { battleId: fortyFourthBattleScenario.id });
return;
}
if (campaign.step === 'forty-fifth-battle') {
this.scene.start('BattleScene', { battleId: fortyFifthBattleScenario.id });
return;
}
if (campaign.step === 'forty-sixth-battle') {
this.scene.start('BattleScene', { battleId: fortySixthBattleScenario.id });
return;
}
if (campaign.step === 'forty-seventh-battle') {
this.scene.start('BattleScene', { battleId: fortySeventhBattleScenario.id });
return;
}
if (campaign.step === 'forty-eighth-battle') {
this.scene.start('BattleScene', { battleId: fortyEighthBattleScenario.id });
return;
}
if (campaign.step === 'forty-ninth-battle') {
this.scene.start('BattleScene', { battleId: fortyNinthBattleScenario.id });
return;
}
if (campaign.step === 'fiftieth-battle') {
this.scene.start('BattleScene', { battleId: fiftiethBattleScenario.id });
return;
}
if (campaign.step === 'fifty-first-battle') {
this.scene.start('BattleScene', { battleId: fiftyFirstBattleScenario.id });
return;
}
if (campaign.step === 'fifty-second-battle') {
this.scene.start('BattleScene', { battleId: fiftySecondBattleScenario.id });
return;
}
if (campaign.step === 'fifty-third-battle') {
this.scene.start('BattleScene', { battleId: fiftyThirdBattleScenario.id });
return;
}
if (campaign.step === 'fifty-fourth-battle') {
this.scene.start('BattleScene', { battleId: fiftyFourthBattleScenario.id });
return;
}
if (campaign.step === 'fifty-fifth-battle') {
this.scene.start('BattleScene', { battleId: fiftyFifthBattleScenario.id });
return;
}
if (campaign.step === 'fifty-sixth-battle') {
this.scene.start('BattleScene', { battleId: fiftySixthBattleScenario.id });
return;
}
if (campaign.step === 'fifty-seventh-battle') {
this.scene.start('BattleScene', { battleId: fiftySeventhBattleScenario.id });
return;
}
if (campaign.step === 'fifty-eighth-battle') {
this.scene.start('BattleScene', { battleId: fiftyEighthBattleScenario.id });
return;
}
if (campaign.step === 'fifty-ninth-battle') {
this.scene.start('BattleScene', { battleId: fiftyNinthBattleScenario.id });
return;
}
if (campaign.step === 'sixtieth-battle') {
this.scene.start('BattleScene', { battleId: sixtiethBattleScenario.id });
return;
}
if (campaign.step === 'sixty-first-battle') {
this.scene.start('BattleScene', { battleId: sixtyFirstBattleScenario.id });
return;
}
if (campaign.step === 'sixty-second-battle') {
this.scene.start('BattleScene', { battleId: sixtySecondBattleScenario.id });
return;
}
if (campaign.step === 'sixty-third-battle') {
this.scene.start('BattleScene', { battleId: sixtyThirdBattleScenario.id });
return;
}
if (campaign.step === 'sixty-fourth-battle') {
this.scene.start('BattleScene', { battleId: sixtyFourthBattleScenario.id });
return;
}
if (campaign.step === 'sixty-fifth-battle') {
this.scene.start('BattleScene', { battleId: sixtyFifthBattleScenario.id });
return;
}
if (campaign.step === 'sixty-sixth-battle') {
this.scene.start('BattleScene', { battleId: sixtySixthBattleScenario.id });
const battleId = battleIdForCampaignStep(campaign.step);
if (battleId) {
await this.navigateTo('BattleScene', { battleId });
return;
}
if (campaign.step === 'first-victory-story') {
this.scene.start('StoryScene', { pages: firstBattleVictoryPages, nextScene: 'TitleScene' });
const { firstBattleVictoryPages } = await import('../data/scenario');
await this.navigateTo('StoryScene', { pages: firstBattleVictoryPages, nextScene: 'TitleScene' });
return;
}
this.scene.start('StoryScene');
await this.navigateTo('StoryScene');
}
private async navigateTo(sceneKey: 'StoryScene' | 'BattleScene' | 'CampScene' | 'EndingScene', data?: Record<string, unknown>) {
if (this.navigating) {
return;
}
this.navigating = true;
try {
await startLazyScene(this, sceneKey, data);
} catch (error) {
console.error(`Failed to start ${sceneKey}`, error);
this.navigating = false;
}
}
}