fix unit tests

This commit is contained in:
ImperialSympathizer 2024-07-08 18:09:38 -04:00
parent 7b35efe95e
commit cf43589260
6 changed files with 31 additions and 14 deletions

View File

@ -118,9 +118,9 @@ export const EGG_GACHA_PULL_COUNT_OVERRIDE: number = 0;
*/ */
// 1 to 256, set to null to ignore // 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_TIER_OVERRIDE: MysteryEncounterTier = null;
export const MYSTERY_ENCOUNTER_OVERRIDE: MysteryEncounterType = MysteryEncounterType.SHADY_VITAMIN_DEALER; export const MYSTERY_ENCOUNTER_OVERRIDE: MysteryEncounterType = null;
/** /**
* MODIFIER / ITEM OVERRIDES * MODIFIER / ITEM OVERRIDES

View File

@ -67,7 +67,7 @@ import { TrainerType } from "#enums/trainer-type";
import { BattlePhase } from "#app/phases/battle-phase"; import { BattlePhase } from "#app/phases/battle-phase";
import { MysteryEncounterVariant } from "#app/data/mystery-encounter"; import { MysteryEncounterVariant } from "#app/data/mystery-encounter";
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phase"; 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"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
const { t } = i18next; const { t } = i18next;
@ -1081,12 +1081,12 @@ export class EncounterPhase extends BattlePhase {
const showNextDialogue = () => { const showNextDialogue = () => {
const nextAction = i === introDialogue.length - 1 ? doShowEncounterOptions : showNextDialogue; const nextAction = i === introDialogue.length - 1 ? doShowEncounterOptions : showNextDialogue;
const dialogue = introDialogue[i]; const dialogue = introDialogue[i];
const title = dialogue.speaker; const title = getTextWithEncounterDialogueTokensAndColor(this.scene, dialogue.speaker);
const text = dialogue.text; const text = getTextWithEncounterDialogueTokensAndColor(this.scene, dialogue.text);
if (title) { 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 { } 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++; i++;
}; };

View File

@ -4,6 +4,7 @@ import GameManager from "#app/test/utils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import {Species} from "#enums/species"; import {Species} from "#enums/species";
import {MysteryEncounterPhase} from "#app/phases/mystery-encounter-phase"; import {MysteryEncounterPhase} from "#app/phases/mystery-encounter-phase";
import {MysteryEncounterType} from "#enums/mystery-encounter-type";
describe("Mystery Encounters", () => { describe("Mystery Encounters", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -23,6 +24,14 @@ describe("Mystery Encounters", () => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
vi.spyOn(overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(256); vi.spyOn(overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(256);
vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(11); 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() => { it("Spawns a mystery encounter", async() => {

View File

@ -28,6 +28,14 @@ describe("Mystery Encounter Phases", () => {
game = new GameManager(phaserGame); game = new GameManager(phaserGame);
vi.spyOn(overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(256); vi.spyOn(overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(256);
vi.spyOn(overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(11); 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", () => { describe("MysteryEncounterPhase", () => {
@ -42,7 +50,6 @@ describe("Mystery Encounter Phases", () => {
}); });
it("Runs MysteryEncounterPhase", async() => { it("Runs MysteryEncounterPhase", async() => {
vi.spyOn(overrides, "MYSTERY_ENCOUNTER_OVERRIDE", "get").mockReturnValue(MysteryEncounterType.MYSTERIOUS_CHALLENGERS);
await game.runToMysteryEncounter([ await game.runToMysteryEncounter([
Species.CHARIZARD, Species.CHARIZARD,
Species.VOLCARONA Species.VOLCARONA
@ -61,7 +68,6 @@ describe("Mystery Encounter Phases", () => {
}); });
it("Selects an option for MysteryEncounterPhase", async() => { 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 dialogueSpy = vi.spyOn(game.scene.ui, "showDialogue");
const messageSpy = vi.spyOn(game.scene.ui, "showText"); const messageSpy = vi.spyOn(game.scene.ui, "showText");
await game.runToMysteryEncounter([ await game.runToMysteryEncounter([
@ -74,7 +80,7 @@ describe("Mystery Encounter Phases", () => {
const handler = game.scene.ui.getHandler() as MysteryEncounterUiHandler; const handler = game.scene.ui.getHandler() as MysteryEncounterUiHandler;
handler.unblockInput(); handler.unblockInput();
handler.processInput(Button.ACTION); handler.processInput(Button.ACTION);
}); }, () => !game.isCurrentPhase(MysteryEncounterPhase));
await game.phaseInterceptor.run(MysteryEncounterPhase); await game.phaseInterceptor.run(MysteryEncounterPhase);
// After option selected // After option selected
@ -83,7 +89,7 @@ describe("Mystery Encounter Phases", () => {
expect(dialogueSpy).toHaveBeenCalledTimes(1); expect(dialogueSpy).toHaveBeenCalledTimes(1);
expect(messageSpy).toHaveBeenCalledTimes(2); expect(messageSpy).toHaveBeenCalledTimes(2);
expect(dialogueSpy).toHaveBeenCalledWith("What's this?", "???", null, expect.any(Function)); 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); expect(messageSpy).toHaveBeenCalledWith("[color=#f8f8f8][shadow=#6b5a73]The trainer steps forward...[/color][/shadow]", null, expect.any(Function), 750, true);
}); });
}); });

View File

@ -34,6 +34,7 @@ import { Button } from "#enums/buttons";
import { BattlerIndex } from "#app/battle.js"; import { BattlerIndex } from "#app/battle.js";
import TargetSelectUiHandler from "#app/ui/target-select-ui-handler.js"; import TargetSelectUiHandler from "#app/ui/target-select-ui-handler.js";
import BattleMessageUiHandler from "#app/ui/battle-message-ui-handler"; 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. * Class to manage the game state and transitions between phases.
@ -152,12 +153,12 @@ export default class GameManager {
const selectStarterPhase = new SelectStarterPhase(this.scene); const selectStarterPhase = new SelectStarterPhase(this.scene);
this.scene.pushPhase(new EncounterPhase(this.scene, false)); this.scene.pushPhase(new EncounterPhase(this.scene, false));
selectStarterPhase.initBattle(starters); selectStarterPhase.initBattle(starters);
}); }, () => this.isCurrentPhase(EncounterPhase));
this.onNextPrompt("EncounterPhase", Mode.MESSAGE, () => { this.onNextPrompt("EncounterPhase", Mode.MESSAGE, () => {
const handler = this.scene.ui.getHandler() as BattleMessageUiHandler; const handler = this.scene.ui.getHandler() as BattleMessageUiHandler;
handler.processInput(Button.ACTION); handler.processInput(Button.ACTION);
}, null, true); }, () => this.isCurrentPhase(MysteryEncounterPhase), true);
await this.phaseInterceptor.run(EncounterPhase); await this.phaseInterceptor.run(EncounterPhase);
} }

View File

@ -290,7 +290,8 @@ export default class PhaseInterceptor {
* @param phase - The phase to start. * @param phase - The phase to start.
*/ */
setMode(mode: Mode, ...args: any[]): Promise<void> { setMode(mode: Mode, ...args: any[]): Promise<void> {
const currentPhase = this.scene.getCurrentPhase(); const currentPhase = this.
scene.getCurrentPhase();
const instance = this.scene.ui; const instance = this.scene.ui;
console.log("setMode", mode, args); console.log("setMode", mode, args);
const ret = this.originalSetMode.apply(instance, [mode, ...args]); const ret = this.originalSetMode.apply(instance, [mode, ...args]);