add overrides helper to gameManager

This commit is contained in:
Felix Staud 2024-07-16 15:17:04 -07:00
parent 75bf80cbad
commit cb4162252c
2 changed files with 48 additions and 0 deletions

View File

@ -35,6 +35,7 @@ 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";
import { OverridesHelper } from "./overridesHelper";
/**
* Class to manage the game state and transitions between phases.
@ -45,6 +46,7 @@ export default class GameManager {
public phaseInterceptor: PhaseInterceptor;
public textInterceptor: TextInterceptor;
public inputsHandler: InputsHandler;
public readonly override: OverridesHelper;
/**
* Creates an instance of GameManager.
@ -60,6 +62,7 @@ export default class GameManager {
this.phaseInterceptor = new PhaseInterceptor(this.scene);
this.textInterceptor = new TextInterceptor(this.scene);
this.gameWrapper.setScene(this.scene);
this.override = new OverridesHelper();
}
/**

View File

@ -0,0 +1,45 @@
import { Biome } from "#app/enums/biome";
import * as Overrides from "#app/overrides";
import { vi } from "vitest";
/**
* Helper to handle overrides in tests
*/
export class OverridesHelper {
constructor() {}
/**
* Set the encounter chance for a mystery encounter.
* @param percentage the encounter chance in %
*/
mysteryEncounterChance(percentage: number) {
const maxRate: number = 256; // 100%
const rate = maxRate * (percentage / 100);
vi.spyOn(Overrides, "MYSTERY_ENCOUNTER_RATE_OVERRIDE", "get").mockReturnValue(rate);
this.log(`Mystery encounter chance set to ${percentage}% (=${rate})!`);
}
/**
* Set the starting biome
* @warning The biome will not be overridden unless you call `workaround_reInitSceneWithOverrides()` (testUtils)
* @param biome the biome to set
*/
startingBiome(biome: Biome) {
vi.spyOn(Overrides, "STARTING_BIOME_OVERRIDE", "get").mockReturnValue(biome);
this.log(`Starting biome set to ${Biome[biome]} (=${biome})!`);
}
/**
* Set the starting wave (index)
*
* @param wave the wave (index) to set. Classic: `1`-`200`
*/
startingWave(wave: number) {
vi.spyOn(Overrides, "STARTING_WAVE_OVERRIDE", "get").mockReturnValue(wave);
this.log(`Starting wave set to ${wave}!`);
}
private log(...params: any[]) {
console.log("Overrides:", ...params);
}
}