maybe fixed bug

This commit is contained in:
Bertie690 2025-08-01 20:25:31 -04:00
parent 5bfcca3b53
commit 6dfddea403
3 changed files with 16 additions and 11 deletions

View File

@ -37,12 +37,14 @@ import { FieldHelper } from "#test/test-utils/helpers/field-helper";
import { ModifierHelper } from "#test/test-utils/helpers/modifiers-helper"; import { ModifierHelper } from "#test/test-utils/helpers/modifiers-helper";
import { MoveHelper } from "#test/test-utils/helpers/move-helper"; import { MoveHelper } from "#test/test-utils/helpers/move-helper";
import { OverridesHelper } from "#test/test-utils/helpers/overrides-helper"; import { OverridesHelper } from "#test/test-utils/helpers/overrides-helper";
import { PromptHandler } from "#test/test-utils/helpers/prompt-handler";
import { ReloadHelper } from "#test/test-utils/helpers/reload-helper"; import { ReloadHelper } from "#test/test-utils/helpers/reload-helper";
import { SettingsHelper } from "#test/test-utils/helpers/settings-helper"; import { SettingsHelper } from "#test/test-utils/helpers/settings-helper";
import type { InputsHandler } from "#test/test-utils/inputs-handler"; import type { InputsHandler } from "#test/test-utils/inputs-handler";
import { MockFetch } from "#test/test-utils/mocks/mock-fetch"; import { MockFetch } from "#test/test-utils/mocks/mock-fetch";
import { PhaseInterceptor } from "#test/test-utils/phase-interceptor"; import { PhaseInterceptor } from "#test/test-utils/phase-interceptor";
import { TextInterceptor } from "#test/test-utils/text-interceptor"; import { TextInterceptor } from "#test/test-utils/text-interceptor";
import type { PhaseString } from "#types/phase-types";
import type { BallUiHandler } from "#ui/ball-ui-handler"; import type { BallUiHandler } from "#ui/ball-ui-handler";
import type { BattleMessageUiHandler } from "#ui/battle-message-ui-handler"; import type { BattleMessageUiHandler } from "#ui/battle-message-ui-handler";
import type { CommandUiHandler } from "#ui/command-ui-handler"; import type { CommandUiHandler } from "#ui/command-ui-handler";
@ -64,6 +66,7 @@ export class GameManager {
public phaseInterceptor: PhaseInterceptor; public phaseInterceptor: PhaseInterceptor;
public textInterceptor: TextInterceptor; public textInterceptor: TextInterceptor;
public inputsHandler: InputsHandler; public inputsHandler: InputsHandler;
public readonly promptHandler: PromptHandler;
public readonly override: OverridesHelper; public readonly override: OverridesHelper;
public readonly move: MoveHelper; public readonly move: MoveHelper;
public readonly classicMode: ClassicModeHelper; public readonly classicMode: ClassicModeHelper;
@ -88,14 +91,14 @@ export class GameManager {
if (globalScene) { if (globalScene) {
this.scene = globalScene; this.scene = globalScene;
this.phaseInterceptor = new PhaseInterceptor(this.scene);
} else { } else {
this.scene = new BattleScene(); this.scene = new BattleScene();
this.phaseInterceptor = new PhaseInterceptor(this.scene);
this.gameWrapper.setScene(this.scene); this.gameWrapper.setScene(this.scene);
firstTimeScene = true; firstTimeScene = true;
} }
this.phaseInterceptor = new PhaseInterceptor(this.scene);
if (!firstTimeScene) { if (!firstTimeScene) {
this.scene.reset(false, true); this.scene.reset(false, true);
(this.scene.ui.handlers[UiMode.STARTER_SELECT] as StarterSelectUiHandler).clearStarterPreferences(); (this.scene.ui.handlers[UiMode.STARTER_SELECT] as StarterSelectUiHandler).clearStarterPreferences();
@ -103,11 +106,10 @@ export class GameManager {
// Must be run after phase interceptor has been initialized. // Must be run after phase interceptor has been initialized.
this.scene.phaseManager.toTitleScreen(true); this.scene.phaseManager.toTitleScreen(true);
this.scene.phaseManager.shiftPhase(); this.scene.phaseManager.shiftPhase();
this.gameWrapper.scene = this.scene;
} }
this.textInterceptor = new TextInterceptor(this.scene); this.textInterceptor = new TextInterceptor(this.scene);
this.promptHandler = new PromptHandler(this);
this.override = new OverridesHelper(this); this.override = new OverridesHelper(this);
this.move = new MoveHelper(this); this.move = new MoveHelper(this);
this.classicMode = new ClassicModeHelper(this); this.classicMode = new ClassicModeHelper(this);
@ -139,7 +141,7 @@ export class GameManager {
*/ */
waitMode(mode: UiMode): Promise<void> { waitMode(mode: UiMode): Promise<void> {
return new Promise(async resolve => { return new Promise(async resolve => {
await waitUntil(() => this.scene.ui?.getMode() === mode); await vi.waitUntil(() => this.scene.ui?.getMode() === mode);
return resolve(); return resolve();
}); });
} }
@ -158,15 +160,18 @@ export class GameManager {
* @param mode - The mode to wait for. * @param mode - The mode to wait for.
* @param callback - The callback function to execute on next prompt. * @param callback - The callback function to execute on next prompt.
* @param expireFn - Optional function to determine if the prompt has expired. * @param expireFn - Optional function to determine if the prompt has expired.
* @param awaitingActionInput - If true, will prevent the prompt from activating until the current {@linkcode AwaitableUiHandler}
* is awaiting input; default `false`
* @todo Remove in favor of {@linkcode promptHandler.addToNextPrompt}
*/ */
onNextPrompt( onNextPrompt(
phaseTarget: string, phaseTarget: PhaseString,
mode: UiMode, mode: UiMode,
callback: () => void, callback: () => void,
expireFn?: () => void, expireFn?: () => boolean,
awaitingActionInput = false, awaitingActionInput = false,
) { ) {
this.phaseInterceptor.addToNextPrompt(phaseTarget, mode, callback, expireFn, awaitingActionInput); this.promptHandler.addToNextPrompt(phaseTarget, mode, callback, expireFn, awaitingActionInput);
} }
/** /**
@ -487,7 +492,7 @@ export class GameManager {
* @param inPhase - Which phase to expect the selection to occur in. Defaults to `SwitchPhase` * @param inPhase - Which phase to expect the selection to occur in. Defaults to `SwitchPhase`
* (which is where the majority of non-command switch operations occur). * (which is where the majority of non-command switch operations occur).
*/ */
doSelectPartyPokemon(slot: number, inPhase = "SwitchPhase") { doSelectPartyPokemon(slot: number, inPhase: PhaseString = "SwitchPhase") {
this.onNextPrompt(inPhase, UiMode.PARTY, () => { this.onNextPrompt(inPhase, UiMode.PARTY, () => {
const partyHandler = this.scene.ui.getHandler() as PartyUiHandler; const partyHandler = this.scene.ui.getHandler() as PartyUiHandler;

View File

@ -75,7 +75,7 @@ export class GameWrapper {
/** /**
* Initialize the given {@linkcode BattleScene} and override various properties to avoid crashes with headless games. * Initialize the given {@linkcode BattleScene} and override various properties to avoid crashes with headless games.
* @param scene - The {@linkcode BattleScene} to initialize. * @param scene - The {@linkcode BattleScene} to initialize
* @returns A Promise that resolves once the initialization process has completed. * @returns A Promise that resolves once the initialization process has completed.
*/ */
// TODO: is asset loading & method overriding actually needed for a headless renderer? // TODO: is asset loading & method overriding actually needed for a headless renderer?

View File

@ -90,7 +90,7 @@ export class PhaseInterceptor {
currentPhase = pm.getCurrentPhase()!; currentPhase = pm.getCurrentPhase()!;
// TODO: Remove proof-of-concept error throw after signature update // TODO: Remove proof-of-concept error throw after signature update
if (!currentPhase) { if (!currentPhase) {
throw new Error("currentPhase is null after being started!"); throw new Error("currentPhase is null after being started! aaaaaaaaaaa");
} }
if (currentPhase.is(this.target)) { if (currentPhase.is(this.target)) {