Fixed issues with switch phase jank 0.95

This commit is contained in:
Bertie690 2025-09-18 12:19:04 -04:00
parent 6e0d0cd495
commit 9b02a82e12
6 changed files with 18 additions and 54 deletions

View File

@ -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();
}

View File

@ -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, () => {

View File

@ -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<void> {
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)));
}
/**

View File

@ -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<void> {
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);
}
}

View File

@ -45,7 +45,8 @@ const endBySetMode: ReadonlyArray<PhaseString> = [
/**
* 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. */

View File

@ -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)]==================");
}
}