diff --git a/test/mystery-encounter/encounter-test-utils.ts b/test/mystery-encounter/encounter-test-utils.ts index f7cdd5b4cc6..6a4b7025f1c 100644 --- a/test/mystery-encounter/encounter-test-utils.ts +++ b/test/mystery-encounter/encounter-test-utils.ts @@ -1,4 +1,5 @@ import { Status } from "#data/status-effect"; +import { BattleStyle } from "#enums/battle-style"; import { Button } from "#enums/buttons"; import { StatusEffect } from "#enums/status-effect"; import { UiMode } from "#enums/ui-mode"; @@ -8,6 +9,7 @@ import { MessagePhase } from "#phases/message-phase"; import { MysteryEncounterBattlePhase, MysteryEncounterRewardsPhase } from "#phases/mystery-encounter-phases"; import { VictoryPhase } from "#phases/victory-phase"; import type { GameManager } from "#test/test-utils/game-manager"; +import { MockConsole } from "#test/test-utils/mocks/mock-console/mock-console"; import type { MessageUiHandler } from "#ui/message-ui-handler"; import type { MysteryEncounterUiHandler } from "#ui/mystery-encounter-ui-handler"; import type { OptionSelectUiHandler } from "#ui/option-select-ui-handler"; @@ -44,15 +46,10 @@ export async function runMysteryEncounterToEnd( if (!isBattle) { return await game.phaseInterceptor.to("MysteryEncounterRewardsPhase"); } - game.onNextPrompt( - "CheckSwitchPhase", - UiMode.CONFIRM, - () => { - game.setMode(UiMode.MESSAGE); - game.endPhase(); - }, - () => game.isCurrentPhase("CommandPhase") || game.isCurrentPhase("TurnInitPhase"), - ); + if (game.scene.battleStyle === BattleStyle.SWITCH) { + MockConsole.queuePostTestWarning("BattleStyle.SWITCH was used during a test case, swapping to set mode..."); + game.settings.battleStyle(BattleStyle.SET); + } await game.toNextTurn(); } diff --git a/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts b/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts index 67bff488f37..3faef27e685 100644 --- a/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts +++ b/test/mystery-encounter/encounters/bug-type-superfan-encounter.test.ts @@ -362,6 +362,7 @@ describe("Bug-Type Superfan - Mystery Encounter", () => { await game.runToMysteryEncounter(MysteryEncounterType.BUG_TYPE_SUPERFAN, defaultParty); await runMysteryEncounterToEnd(game, 1, undefined, true); await skipBattleRunMysteryEncounterRewardsPhase(game, false); + console.log(game.promptHandler["prompts"]); expect(game).toBeAtPhase("MysteryEncounterRewardsPhase"); game.onNextPrompt("MysteryEncounterRewardsPhase", UiMode.OPTION_SELECT, () => { diff --git a/test/test-utils/game-manager.ts b/test/test-utils/game-manager.ts index db46c3591dd..d3a09fda02b 100644 --- a/test/test-utils/game-manager.ts +++ b/test/test-utils/game-manager.ts @@ -23,7 +23,6 @@ import { NewBattlePhase } from "#phases/new-battle-phase"; import { SelectStarterPhase } from "#phases/select-starter-phase"; import type { SelectTargetPhase } from "#phases/select-target-phase"; import { TurnEndPhase } from "#phases/turn-end-phase"; -import { TurnInitPhase } from "#phases/turn-init-phase"; import { TurnStartPhase } from "#phases/turn-start-phase"; import { generateStarter } from "#test/test-utils/game-manager-utils"; import { GameWrapper } from "#test/test-utils/game-wrapper"; @@ -380,17 +379,6 @@ export class GameManager { async toNextWave(): Promise { this.doSelectModifier(); - // forcibly end the message box for switching pokemon - this.onNextPrompt( - "CheckSwitchPhase", - UiMode.CONFIRM, - () => { - this.setMode(UiMode.MESSAGE); - this.endPhase(); - }, - () => this.isCurrentPhase(TurnInitPhase), - ); - await this.phaseInterceptor.to("TurnInitPhase"); await this.phaseInterceptor.to("CommandPhase"); console.log("==================[New Wave]=================="); @@ -420,8 +408,8 @@ export class GameManager { */ public isCurrentPhase(phaseTargets: PhaseClass): boolean; public isCurrentPhase(...phaseTargets: (PhaseString | PhaseClass)[]): boolean { - const pName = this.scene.phaseManager.getCurrentPhase().phaseName; - return phaseTargets.some(p => (typeof p === "string" ? p : (p.name as PhaseString) === pName)); + const phase = this.scene.phaseManager.getCurrentPhase(); + return phaseTargets.some(p => phase.is(typeof p === "string" ? p : (p.name as PhaseString))); } /** diff --git a/test/test-utils/helpers/classic-mode-helper.ts b/test/test-utils/helpers/classic-mode-helper.ts index f813a8f797e..15547a221ed 100644 --- a/test/test-utils/helpers/classic-mode-helper.ts +++ b/test/test-utils/helpers/classic-mode-helper.ts @@ -110,7 +110,10 @@ export class ClassicModeHelper extends GameManagerHelper { * Queue inputs to switch at the start of the next battle, and then start it. * @param pokemonIndex - The 0-indexed position of the party pokemon to switch to. * Should never be called with 0 as that will select the currently active pokemon and freeze - * @returns A Promise that resolves once the battle has been started and the switch prompt resolved + * @returns A Promise that resolves once the battle has been started and the switch prompt resolved. + * @remarks + * This will temporarily set the current {@linkcode BattleStyle} to `SWITCH` for the duration + * of the `CheckSwitchPhase`. * @todo Make this work for double battles * @example * ```ts @@ -119,7 +122,7 @@ export class ClassicModeHelper extends GameManagerHelper { * ``` */ public async startBattleWithSwitch(pokemonIndex: number): Promise { - this.game.scene.battleStyle = BattleStyle.SWITCH; + this.game.settings.battleStyle(BattleStyle.SWITCH); this.game.onNextPrompt( "CheckSwitchPhase", UiMode.CONFIRM, @@ -133,5 +136,6 @@ export class ClassicModeHelper extends GameManagerHelper { await this.game.phaseInterceptor.to("CommandPhase"); console.log("==================[New Battle (Initial Switch)]=================="); + this.game.settings.battleStyle(BattleStyle.SET); } } diff --git a/test/test-utils/helpers/prompt-handler.ts b/test/test-utils/helpers/prompt-handler.ts index dadc9314c1b..4d9ef8eef05 100644 --- a/test/test-utils/helpers/prompt-handler.ts +++ b/test/test-utils/helpers/prompt-handler.ts @@ -45,7 +45,8 @@ const endBySetMode: ReadonlyArray = [ /** * Helper class to handle executing prompts upon UI mode changes. - * @todo Remove once a UI overhaul + * @todo Remove once a UI overhaul occurs - + * using this correctly effectively requires one to know the entire phase heiarchy */ export class PromptHandler extends GameManagerHelper { /** An array of {@linkcode UIPrompt | prompts} with associated callbacks. */ diff --git a/test/test-utils/helpers/reload-helper.ts b/test/test-utils/helpers/reload-helper.ts index 30ff34ae559..728fe556a3a 100644 --- a/test/test-utils/helpers/reload-helper.ts +++ b/test/test-utils/helpers/reload-helper.ts @@ -1,8 +1,4 @@ -import { BattleStyle } from "#enums/battle-style"; -import { UiMode } from "#enums/ui-mode"; -import { CommandPhase } from "#phases/command-phase"; import { TitlePhase } from "#phases/title-phase"; -import { TurnInitPhase } from "#phases/turn-init-phase"; import type { GameManager } from "#test/test-utils/game-manager"; import { GameManagerHelper } from "#test/test-utils/helpers/game-manager-helper"; import type { SessionSaveData } from "#types/save-data"; @@ -52,30 +48,7 @@ export class ReloadHelper extends GameManagerHelper { } await titlePhase["loadSaveSlot"](-1); // Load the desired session data - // Run through prompts for switching Pokemon, copied from classicModeHelper.ts - if (this.game.scene.battleStyle === BattleStyle.SWITCH) { - this.game.onNextPrompt( - "CheckSwitchPhase", - UiMode.CONFIRM, - () => { - this.game.setMode(UiMode.MESSAGE); - this.game.endPhase(); - }, - () => this.game.isCurrentPhase(CommandPhase) || this.game.isCurrentPhase(TurnInitPhase), - ); - - this.game.onNextPrompt( - "CheckSwitchPhase", - UiMode.CONFIRM, - () => { - this.game.setMode(UiMode.MESSAGE); - this.game.endPhase(); - }, - () => this.game.isCurrentPhase(CommandPhase) || this.game.isCurrentPhase(TurnInitPhase), - ); - } - - await this.game.phaseInterceptor.to(CommandPhase); + await this.game.phaseInterceptor.to("CommandPhase"); console.log("==================[New Turn (Reloaded)]=================="); } }