From cf43589260ecb2030784820d0ad4add5a6b6b10b Mon Sep 17 00:00:00 2001 From: ImperialSympathizer Date: Mon, 8 Jul 2024 18:09:38 -0400 Subject: [PATCH] fix unit tests --- src/overrides.ts | 4 ++-- src/phases.ts | 10 +++++----- .../mystery-encounter/mystery-encounter.test.ts | 9 +++++++++ src/test/phases/mystery-encounter-phase.test.ts | 14 ++++++++++---- src/test/utils/gameManager.ts | 5 +++-- src/test/utils/phaseInterceptor.ts | 3 ++- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/overrides.ts b/src/overrides.ts index f3ac35e2075..6634ca32788 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -118,9 +118,9 @@ export const EGG_GACHA_PULL_COUNT_OVERRIDE: number = 0; */ // 1 to 256, set to null to ignore -export const MYSTERY_ENCOUNTER_RATE_OVERRIDE: number = 256; +export const MYSTERY_ENCOUNTER_RATE_OVERRIDE: number = null; export const MYSTERY_ENCOUNTER_TIER_OVERRIDE: MysteryEncounterTier = null; -export const MYSTERY_ENCOUNTER_OVERRIDE: MysteryEncounterType = MysteryEncounterType.SHADY_VITAMIN_DEALER; +export const MYSTERY_ENCOUNTER_OVERRIDE: MysteryEncounterType = null; /** * MODIFIER / ITEM OVERRIDES diff --git a/src/phases.ts b/src/phases.ts index 6bbc5f2d6d6..4b918008978 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -67,7 +67,7 @@ import { TrainerType } from "#enums/trainer-type"; import { BattlePhase } from "#app/phases/battle-phase"; import { MysteryEncounterVariant } from "#app/data/mystery-encounter"; import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phase"; -import { handleMysteryEncounterVictory } from "#app/data/mystery-encounters/mystery-encounter-utils"; +import { getTextWithEncounterDialogueTokensAndColor, handleMysteryEncounterVictory } from "#app/data/mystery-encounters/mystery-encounter-utils"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; const { t } = i18next; @@ -1081,12 +1081,12 @@ export class EncounterPhase extends BattlePhase { const showNextDialogue = () => { const nextAction = i === introDialogue.length - 1 ? doShowEncounterOptions : showNextDialogue; const dialogue = introDialogue[i]; - const title = dialogue.speaker; - const text = dialogue.text; + const title = getTextWithEncounterDialogueTokensAndColor(this.scene, dialogue.speaker); + const text = getTextWithEncounterDialogueTokensAndColor(this.scene, dialogue.text); if (title) { - this.scene.ui.showDialogue(i18next.t(text), i18next.t(title), null, nextAction, 0, i === 0 ? 750 : 0); + this.scene.ui.showDialogue(text, title, null, nextAction, 0, i === 0 ? 750 : 0); } else { - this.scene.ui.showText(i18next.t(text), null, nextAction, i === 0 ? 750 : 0, true); + this.scene.ui.showText(text, null, nextAction, i === 0 ? 750 : 0, true); } i++; }; diff --git a/src/test/mystery-encounter/mystery-encounter.test.ts b/src/test/mystery-encounter/mystery-encounter.test.ts index 2645fbc68ce..49754a70876 100644 --- a/src/test/mystery-encounter/mystery-encounter.test.ts +++ b/src/test/mystery-encounter/mystery-encounter.test.ts @@ -4,6 +4,7 @@ import GameManager from "#app/test/utils/gameManager"; import Phaser from "phaser"; import {Species} from "#enums/species"; import {MysteryEncounterPhase} from "#app/phases/mystery-encounter-phase"; +import {MysteryEncounterType} from "#enums/mystery-encounter-type"; describe("Mystery Encounters", () => { let phaserGame: Phaser.Game; @@ -23,6 +24,14 @@ describe("Mystery Encounters", () => { game = new GameManager(phaserGame); vi.spyOn(overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(256); vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(11); + vi.spyOn(overrides, "MYSTERY_ENCOUNTER_OVERRIDE", "get").mockReturnValue(MysteryEncounterType.MYSTERIOUS_CHALLENGERS); + + // Seed guarantees wild encounter to be replaced by ME + vi.spyOn(game.scene, "resetSeed").mockImplementation(() => { + game.scene.waveSeed = "test"; + Phaser.Math.RND.sow([ game.scene.waveSeed ]); + game.scene.rngCounter = 0; + }); }); it("Spawns a mystery encounter", async() => { diff --git a/src/test/phases/mystery-encounter-phase.test.ts b/src/test/phases/mystery-encounter-phase.test.ts index 4374fc60bd6..0e9cce09f12 100644 --- a/src/test/phases/mystery-encounter-phase.test.ts +++ b/src/test/phases/mystery-encounter-phase.test.ts @@ -28,6 +28,14 @@ describe("Mystery Encounter Phases", () => { game = new GameManager(phaserGame); vi.spyOn(overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(256); vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(11); + vi.spyOn(overrides, "MYSTERY_ENCOUNTER_OVERRIDE", "get").mockReturnValue(MysteryEncounterType.MYSTERIOUS_CHALLENGERS); + + // Seed guarantees wild encounter to be replaced by ME + vi.spyOn(game.scene, "resetSeed").mockImplementation(() => { + game.scene.waveSeed = "test"; + Phaser.Math.RND.sow([ game.scene.waveSeed ]); + game.scene.rngCounter = 0; + }); }); describe("MysteryEncounterPhase", () => { @@ -42,7 +50,6 @@ describe("Mystery Encounter Phases", () => { }); it("Runs MysteryEncounterPhase", async() => { - vi.spyOn(overrides, "MYSTERY_ENCOUNTER_OVERRIDE", "get").mockReturnValue(MysteryEncounterType.MYSTERIOUS_CHALLENGERS); await game.runToMysteryEncounter([ Species.CHARIZARD, Species.VOLCARONA @@ -61,7 +68,6 @@ describe("Mystery Encounter Phases", () => { }); it("Selects an option for MysteryEncounterPhase", async() => { - vi.spyOn(overrides, "MYSTERY_ENCOUNTER_OVERRIDE", "get").mockReturnValue(MysteryEncounterType.MYSTERIOUS_CHALLENGERS); const dialogueSpy = vi.spyOn(game.scene.ui, "showDialogue"); const messageSpy = vi.spyOn(game.scene.ui, "showText"); await game.runToMysteryEncounter([ @@ -74,7 +80,7 @@ describe("Mystery Encounter Phases", () => { const handler = game.scene.ui.getHandler() as MysteryEncounterUiHandler; handler.unblockInput(); handler.processInput(Button.ACTION); - }); + }, () => !game.isCurrentPhase(MysteryEncounterPhase)); await game.phaseInterceptor.run(MysteryEncounterPhase); // After option selected @@ -83,7 +89,7 @@ describe("Mystery Encounter Phases", () => { expect(dialogueSpy).toHaveBeenCalledTimes(1); expect(messageSpy).toHaveBeenCalledTimes(2); expect(dialogueSpy).toHaveBeenCalledWith("What's this?", "???", null, expect.any(Function)); - expect(messageSpy).toHaveBeenCalledWith("Mysterious challengers have appeared!", null, expect.any(Function), 750, true); + expect(messageSpy).toHaveBeenCalledWith("[color=#f8f8f8][shadow=#6b5a73]Mysterious challengers have appeared![/color][/shadow]", null, expect.any(Function), 750, true); expect(messageSpy).toHaveBeenCalledWith("[color=#f8f8f8][shadow=#6b5a73]The trainer steps forward...[/color][/shadow]", null, expect.any(Function), 750, true); }); }); diff --git a/src/test/utils/gameManager.ts b/src/test/utils/gameManager.ts index bfe13ee127c..4550891dcf9 100644 --- a/src/test/utils/gameManager.ts +++ b/src/test/utils/gameManager.ts @@ -34,6 +34,7 @@ import { Button } from "#enums/buttons"; import { BattlerIndex } from "#app/battle.js"; import TargetSelectUiHandler from "#app/ui/target-select-ui-handler.js"; import BattleMessageUiHandler from "#app/ui/battle-message-ui-handler"; +import {MysteryEncounterPhase} from "#app/phases/mystery-encounter-phase"; /** * Class to manage the game state and transitions between phases. @@ -152,12 +153,12 @@ export default class GameManager { const selectStarterPhase = new SelectStarterPhase(this.scene); this.scene.pushPhase(new EncounterPhase(this.scene, false)); selectStarterPhase.initBattle(starters); - }); + }, () => this.isCurrentPhase(EncounterPhase)); this.onNextPrompt("EncounterPhase", Mode.MESSAGE, () => { const handler = this.scene.ui.getHandler() as BattleMessageUiHandler; handler.processInput(Button.ACTION); - }, null, true); + }, () => this.isCurrentPhase(MysteryEncounterPhase), true); await this.phaseInterceptor.run(EncounterPhase); } diff --git a/src/test/utils/phaseInterceptor.ts b/src/test/utils/phaseInterceptor.ts index e99adce1550..7591b958dbf 100644 --- a/src/test/utils/phaseInterceptor.ts +++ b/src/test/utils/phaseInterceptor.ts @@ -290,7 +290,8 @@ export default class PhaseInterceptor { * @param phase - The phase to start. */ setMode(mode: Mode, ...args: any[]): Promise { - const currentPhase = this.scene.getCurrentPhase(); + const currentPhase = this. + scene.getCurrentPhase(); const instance = this.scene.ui; console.log("setMode", mode, args); const ret = this.originalSetMode.apply(instance, [mode, ...args]);