mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-27 02:32:21 +02:00
More thorough sanitization of overrides
This commit is contained in:
parent
5432cf5377
commit
1b7400a6f2
@ -1240,7 +1240,7 @@ export default class BattleScene extends SceneBase {
|
|||||||
this.field.add(newTrainer);
|
this.field.add(newTrainer);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!this.gameMode.hasTrainers) {
|
if (!this.gameMode.hasTrainers || (Overrides.DISABLE_TRAINERS_OVERRIDE && isNullOrUndefined(trainerData))) {
|
||||||
newBattleType = BattleType.WILD;
|
newBattleType = BattleType.WILD;
|
||||||
} else if (battleType === undefined) {
|
} else if (battleType === undefined) {
|
||||||
newBattleType = this.gameMode.isWaveTrainer(newWaveIndex, this.arena) ? BattleType.TRAINER : BattleType.WILD;
|
newBattleType = this.gameMode.isWaveTrainer(newWaveIndex, this.arena) ? BattleType.TRAINER : BattleType.WILD;
|
||||||
|
@ -244,6 +244,11 @@ class DefaultOverrides {
|
|||||||
* Note that, for all items in the array, `count` is not used.
|
* Note that, for all items in the array, `count` is not used.
|
||||||
*/
|
*/
|
||||||
readonly ITEM_REWARD_OVERRIDE: ModifierOverride[] = [];
|
readonly ITEM_REWARD_OVERRIDE: ModifierOverride[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If `true`, disable all non-scripted opponent trainer encounters.
|
||||||
|
*/
|
||||||
|
readonly DISABLE_TRAINERS_OVERRIDE: boolean = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOverrides = new DefaultOverrides();
|
export const defaultOverrides = new DefaultOverrides();
|
||||||
|
@ -120,9 +120,11 @@ export default class GameManager {
|
|||||||
this.settings = new SettingsHelper(this);
|
this.settings = new SettingsHelper(this);
|
||||||
this.reload = new ReloadHelper(this);
|
this.reload = new ReloadHelper(this);
|
||||||
this.modifiers = new ModifierHelper(this);
|
this.modifiers = new ModifierHelper(this);
|
||||||
|
this.field = new FieldHelper(this);
|
||||||
|
this.override.sanitizeOverrides();
|
||||||
|
|
||||||
// Sanitize overrides for each test
|
// Disables Mystery Encounters on all tests (can be overridden at test level)
|
||||||
this.override.mysteryEncounterChance(0).moveset([]).enemyMoveset([]).startingHeldItems([]).enemyHeldItems([]);
|
this.override.mysteryEncounterChance(0);
|
||||||
|
|
||||||
global.fetch = vi.fn(MockFetch) as any;
|
global.fetch = vi.fn(MockFetch) as any;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
import type { Variant } from "#app/data/variant";
|
import type { Variant } from "#app/data/variant";
|
||||||
import { Weather } from "#app/data/weather";
|
import { Weather } from "#app/data/weather";
|
||||||
import { Abilities } from "#app/enums/abilities";
|
import { Abilities } from "#enums/abilities";
|
||||||
import * as GameMode from "#app/game-mode";
|
|
||||||
import type { GameModes } from "#app/game-mode";
|
|
||||||
import { getGameMode } from "#app/game-mode";
|
|
||||||
import type { ModifierOverride } from "#app/modifier/modifier-type";
|
import type { ModifierOverride } from "#app/modifier/modifier-type";
|
||||||
import type { BattleStyle } from "#app/overrides";
|
import type { BattleStyle } from "#app/overrides";
|
||||||
import Overrides from "#app/overrides";
|
import Overrides, { defaultOverrides } from "#app/overrides";
|
||||||
import type { Unlockables } from "#app/system/unlockables";
|
import type { Unlockables } from "#app/system/unlockables";
|
||||||
import { Biome } from "#enums/biome";
|
import { Biome } from "#enums/biome";
|
||||||
import { Moves } from "#enums/moves";
|
import { Moves } from "#enums/moves";
|
||||||
@ -15,8 +12,9 @@ import type { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
|||||||
import { Species } from "#enums/species";
|
import { Species } from "#enums/species";
|
||||||
import { StatusEffect } from "#enums/status-effect";
|
import { StatusEffect } from "#enums/status-effect";
|
||||||
import type { WeatherType } from "#enums/weather-type";
|
import type { WeatherType } from "#enums/weather-type";
|
||||||
import { vi } from "vitest";
|
import { expect, vi } from "vitest";
|
||||||
import { GameManagerHelper } from "./gameManagerHelper";
|
import { GameManagerHelper } from "#test/utils/helpers/gameManagerHelper";
|
||||||
|
import { shiftCharCodes } from "#app/utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to handle overrides in tests
|
* Helper to handle overrides in tests
|
||||||
@ -226,12 +224,7 @@ export class OverridesHelper extends GameManagerHelper {
|
|||||||
* @returns `this`
|
* @returns `this`
|
||||||
*/
|
*/
|
||||||
public disableTrainerWaves(): this {
|
public disableTrainerWaves(): this {
|
||||||
const realFn = getGameMode;
|
vi.spyOn(Overrides, "DISABLE_TRAINERS_OVERRIDE", "get").mockReturnValue(true);
|
||||||
vi.spyOn(GameMode, "getGameMode").mockImplementation((gameMode: GameModes) => {
|
|
||||||
const mode = realFn(gameMode);
|
|
||||||
mode.hasTrainers = false;
|
|
||||||
return mode;
|
|
||||||
});
|
|
||||||
this.log("Standard trainer waves are disabled!");
|
this.log("Standard trainer waves are disabled!");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -263,11 +256,8 @@ export class OverridesHelper extends GameManagerHelper {
|
|||||||
* @returns `this`
|
* @returns `this`
|
||||||
*/
|
*/
|
||||||
public seed(seed: string): this {
|
public seed(seed: string): this {
|
||||||
vi.spyOn(this.game.scene, "resetSeed").mockImplementation(() => {
|
// Shift the seed here with a negative wave number, to compensate for `resetSeed()` shifting the seed itself.
|
||||||
this.game.scene.waveSeed = seed;
|
this.game.scene.setSeed(shiftCharCodes(seed, (this.game.scene.currentBattle?.waveIndex ?? 0) * -1));
|
||||||
Phaser.Math.RND.sow([ seed ]);
|
|
||||||
this.game.scene.rngCounter = 0;
|
|
||||||
});
|
|
||||||
this.game.scene.resetSeed();
|
this.game.scene.resetSeed();
|
||||||
this.log(`Seed set to "${seed}"!`);
|
this.log(`Seed set to "${seed}"!`);
|
||||||
return this;
|
return this;
|
||||||
@ -539,4 +529,14 @@ export class OverridesHelper extends GameManagerHelper {
|
|||||||
private log(...params: any[]) {
|
private log(...params: any[]) {
|
||||||
console.log("Overrides:", ...params);
|
console.log("Overrides:", ...params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sanitizeOverrides(): void {
|
||||||
|
for (const key of Object.keys(defaultOverrides)) {
|
||||||
|
if (Overrides[key] !== defaultOverrides[key]) {
|
||||||
|
vi.spyOn(Overrides, key as any, "get").mockReturnValue(defaultOverrides[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Overrides).toEqual(defaultOverrides);
|
||||||
|
this.log("Sanitizing all overrides!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,10 @@ vi.mock("#app/overrides", async (importOriginal) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
default: defaultOverrides,
|
default: defaultOverrides,
|
||||||
defaultOverrides,
|
// Export `defaultOverrides` as a *copy*.
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
// This ensures we can easily reset `overrides` back to its default values after modifying it.
|
||||||
} satisfies typeof import("#app/overrides");
|
defaultOverrides: { ...defaultOverrides },
|
||||||
|
} satisfies typeof import("#app/overrides"); // eslint-disable-line
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user