diff --git a/src/game/scenes/BattleScene.ts b/src/game/scenes/BattleScene.ts index a98de06..2f62d6d 100644 --- a/src/game/scenes/BattleScene.ts +++ b/src/game/scenes/BattleScene.ts @@ -1132,6 +1132,7 @@ type TurnEndPromptOptions = { type BattleSceneData = { battleId?: string; + selectedSortieUnitIds?: string[]; }; type CommandButton = { @@ -2971,6 +2972,7 @@ export class BattleScene extends Phaser.Scene { private edgeScrollElapsed = 0; private suppressNextLeftClick = false; private approachPathCostCache = new Map>(); + private launchSortieUnitIds: string[] = []; constructor() { super('BattleScene'); @@ -2978,6 +2980,7 @@ export class BattleScene extends Phaser.Scene { init(data?: BattleSceneData) { configureBattleScenario(getBattleScenario(data?.battleId)); + this.launchSortieUnitIds = this.normalizeLaunchSortieUnitIds(data?.selectedSortieUnitIds); } create() { @@ -3161,7 +3164,7 @@ export class BattleScene extends Phaser.Scene { } private resetBattleData(campaign?: CampaignState) { - const selected = new Set(campaign?.selectedSortieUnitIds ?? []); + const selected = new Set(this.effectiveSortieUnitIds(campaign)); const forcedAllyIds = new Set( battleScenario.defeatConditions .filter((condition) => condition.kind === 'unit-defeated') @@ -3177,6 +3180,14 @@ export class BattleScene extends Phaser.Scene { initialBattleBonds = battleBonds.map(cloneBattleBond); } + private normalizeLaunchSortieUnitIds(unitIds?: string[]) { + return [...new Set((unitIds ?? []).map((unitId) => unitId.trim()).filter(Boolean))]; + } + + private effectiveSortieUnitIds(campaign?: CampaignState) { + return this.launchSortieUnitIds.length > 0 ? this.launchSortieUnitIds : campaign?.selectedSortieUnitIds ?? []; + } + private applyCampaignUnitProgress(unit: UnitData, campaign?: CampaignState) { const cloned = cloneUnitData(unit); const progress = campaign?.roster.find((candidate) => candidate.id === unit.id); @@ -12478,12 +12489,17 @@ export class BattleScene extends Phaser.Scene { } getDebugState() { + const effectiveSortieUnitIds = this.effectiveSortieUnitIds(getCampaignState()); + const deployedAllyIds = battleUnits.filter((unit) => unit.faction === 'ally').map((unit) => unit.id); + return { scene: this.scene.key, battleId: battleScenario.id, battleTitle: battleScenario.title, victoryConditionLabel: battleScenario.victoryConditionLabel, defeatConditionLabel: battleScenario.defeatConditionLabel, + selectedSortieUnitIds: effectiveSortieUnitIds, + deployedAllyIds, turnNumber: this.turnNumber, activeFaction: this.activeFaction, phase: this.phase, diff --git a/src/game/scenes/CampScene.ts b/src/game/scenes/CampScene.ts index 0f57128..a62d8fd 100644 --- a/src/game/scenes/CampScene.ts +++ b/src/game/scenes/CampScene.ts @@ -12077,10 +12077,11 @@ export class CampScene extends Phaser.Scene { } markCampaignStep(flow.campaignStep); + const selectedSortieUnitIds = [...this.selectedSortieUnitIds]; void startLazyScene(this, 'StoryScene', { pages: flow.pages, nextScene: 'BattleScene', - nextSceneData: { battleId: flow.nextBattleId } + nextSceneData: { battleId: flow.nextBattleId, selectedSortieUnitIds } }); } diff --git a/src/game/scenes/TitleScene.ts b/src/game/scenes/TitleScene.ts index 2f586e4..9af82e7 100644 --- a/src/game/scenes/TitleScene.ts +++ b/src/game/scenes/TitleScene.ts @@ -319,7 +319,7 @@ export class TitleScene extends Phaser.Scene { const battleId = battleIdForCampaignStep(campaign.step); if (battleId) { - await this.navigateTo('BattleScene', { battleId }); + await this.navigateTo('BattleScene', { battleId, selectedSortieUnitIds: campaign.selectedSortieUnitIds }); return; }