[Test] Speed up tests and make enemy item override remove existing items (#4203)

* Make enemy held items override remove randomly generated items

Remove cries from tests

* Override callback delays to 1ms
This commit is contained in:
NightKev 2024-09-12 22:09:12 -07:00 committed by GitHub
parent 5f918ca001
commit 5f9bd21a51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 10 deletions

View File

@ -21,7 +21,7 @@ import Overrides from "#app/overrides";
import { ModifierType, modifierTypes } from "./modifier-type"; import { ModifierType, modifierTypes } from "./modifier-type";
import { Command } from "#app/ui/command-ui-handler"; import { Command } from "#app/ui/command-ui-handler";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { Stat, type PermanentStat, type TempBattleStat, BATTLE_STATS, TEMP_BATTLE_STATS } from "#app/enums/stat"; import { Stat, type PermanentStat, type TempBattleStat, BATTLE_STATS, TEMP_BATTLE_STATS } from "#app/enums/stat";
import i18next from "i18next"; import i18next from "i18next";
import { allMoves } from "#app/data/move"; import { allMoves } from "#app/data/move";
@ -2947,6 +2947,10 @@ export function overrideHeldItems(scene: BattleScene, pokemon: Pokemon, isPlayer
return; return;
} }
if (!isPlayer) {
scene.clearEnemyHeldItemModifiers();
}
heldItemsOverride.forEach(item => { heldItemsOverride.forEach(item => {
const modifierFunc = modifierTypes[item.name]; const modifierFunc = modifierTypes[item.name];
let modifierType: ModifierType | null = modifierFunc(); let modifierType: ModifierType | null = modifierFunc();

View File

@ -24,7 +24,6 @@ import { TurnInitPhase } from "#app/phases/turn-init-phase";
import { TurnStartPhase } from "#app/phases/turn-start-phase"; import { TurnStartPhase } from "#app/phases/turn-start-phase";
import ErrorInterceptor from "#app/test/utils/errorInterceptor"; import ErrorInterceptor from "#app/test/utils/errorInterceptor";
import InputsHandler from "#app/test/utils/inputsHandler"; import InputsHandler from "#app/test/utils/inputsHandler";
import { MockClock } from "#app/test/utils/mocks/mockClock";
import CommandUiHandler from "#app/ui/command-ui-handler"; import CommandUiHandler from "#app/ui/command-ui-handler";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler"; import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import PartyUiHandler from "#app/ui/party-ui-handler"; import PartyUiHandler from "#app/ui/party-ui-handler";
@ -360,12 +359,10 @@ export default class GameManager {
} }
async killPokemon(pokemon: PlayerPokemon | EnemyPokemon) { async killPokemon(pokemon: PlayerPokemon | EnemyPokemon) {
(this.scene.time as MockClock).overrideDelay = 0.01;
return new Promise<void>(async (resolve, reject) => { return new Promise<void>(async (resolve, reject) => {
pokemon.hp = 0; pokemon.hp = 0;
this.scene.pushPhase(new FaintPhase(this.scene, pokemon.getBattlerIndex(), true)); this.scene.pushPhase(new FaintPhase(this.scene, pokemon.getBattlerIndex(), true));
await this.phaseInterceptor.to(FaintPhase).catch((e) => reject(e)); await this.phaseInterceptor.to(FaintPhase).catch((e) => reject(e));
(this.scene.time as MockClock).overrideDelay = undefined;
resolve(); resolve();
}); });
} }

View File

@ -87,6 +87,8 @@ export default class GameWrapper {
}); });
Pokemon.prototype.enableMask = () => null; Pokemon.prototype.enableMask = () => null;
Pokemon.prototype.updateFusionPalette = () => null; Pokemon.prototype.updateFusionPalette = () => null;
Pokemon.prototype.cry = () => null;
Pokemon.prototype.faintCry = (cb) => { if (cb) cb(); };
} }
setScene(scene: BattleScene) { setScene(scene: BattleScene) {

View File

@ -2,23 +2,22 @@ import Clock = Phaser.Time.Clock;
export class MockClock extends Clock { export class MockClock extends Clock {
public overrideDelay: number | undefined; public overrideDelay: number | null = 1;
constructor(scene) { constructor(scene) {
super(scene); super(scene);
this.overrideDelay = undefined;
setInterval(() => { setInterval(() => {
/* /*
To simulate frame update To simulate frame update
eventEmitter.on(SceneEvents.PRE_UPDATE, this.preUpdate, this); eventEmitter.on(SceneEvents.PRE_UPDATE, this.preUpdate, this);
eventEmitter.on(SceneEvents.UPDATE, this.update, this); eventEmitter.on(SceneEvents.UPDATE, this.update, this);
*/ */
this.preUpdate(this.systems.game.loop.time, 100); this.preUpdate(this.systems.game.loop.time, 1);
this.update(this.systems.game.loop.time, 100); this.update(this.systems.game.loop.time, 1);
}, 100); }, 1);
} }
addEvent(config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig): Phaser.Time.TimerEvent { addEvent(config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig): Phaser.Time.TimerEvent {
const cfg = { ...config, delay: this.overrideDelay || config.delay}; const cfg = { ...config, delay: this.overrideDelay ?? config.delay};
return super.addEvent(cfg); return super.addEvent(cfg);
} }
} }