From 94e43e633c93434c060feec3ba52bbc5a0b6917a Mon Sep 17 00:00:00 2001 From: Felix Staud Date: Tue, 16 Jul 2024 16:41:47 -0700 Subject: [PATCH] add encounterTestUtils.ts --- .../mystery-encounter/encounterTestUtils.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/mystery-encounter/encounterTestUtils.ts diff --git a/src/test/mystery-encounter/encounterTestUtils.ts b/src/test/mystery-encounter/encounterTestUtils.ts new file mode 100644 index 00000000000..1fb0d0bbc17 --- /dev/null +++ b/src/test/mystery-encounter/encounterTestUtils.ts @@ -0,0 +1,54 @@ +import { Button } from "#app/enums/buttons.js"; +import { MessagePhase } from "#app/phases.js"; +import { MysteryEncounterOptionSelectedPhase, MysteryEncounterPhase } from "#app/phases/mystery-encounter-phase.js"; +import MysteryEncounterUiHandler from "#app/ui/mystery-encounter-ui-handler.js"; +import { Mode } from "#app/ui/ui.js"; +import GameManager from "../utils/gameManager"; + +export async function runSelectMysteryEncounterOption(game: GameManager, optionNo: number) { + // Handle eventual weather messages (e.g. a downpour started!) + if (game.isCurrentPhase(MessagePhase)) { + game.onNextPrompt("MessagePhase", Mode.MESSAGE, () => { + const uiHandler = game.scene.ui.getHandler(); + uiHandler.processInput(Button.ACTION); + }); + await game.phaseInterceptor.run(MessagePhase); + } + + // dispose of intro messages + game.onNextPrompt("MysteryEncounterPhase", Mode.MESSAGE, () => { + const uiHandler = game.scene.ui.getHandler(); + uiHandler.processInput(Button.ACTION); + }); + // select the desired option + game.onNextPrompt("MysteryEncounterPhase", Mode.MYSTERY_ENCOUNTER, () => { + const uiHandler = game.scene.ui.getHandler(); + uiHandler.unblockInput(); + + switch (optionNo) { + case 1: + // no movement needed. Default cursor position + break; + case 2: + uiHandler.processInput(Button.RIGHT); + break; + case 3: + uiHandler.processInput(Button.DOWN); + break; + case 4: + uiHandler.processInput(Button.RIGHT); + uiHandler.processInput(Button.DOWN); + break; + } + + uiHandler.processInput(Button.ACTION); + }); + await game.phaseInterceptor.run(MysteryEncounterPhase); + + // run the selected options phase + game.onNextPrompt("MysteryEncounterOptionSelectedPhase", Mode.MESSAGE, () => { + const uiHandler = game.scene.ui.getHandler(); + uiHandler.processInput(Button.ACTION); + }); + await game.phaseInterceptor.run(MysteryEncounterOptionSelectedPhase); +}