[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

@ -2947,6 +2947,10 @@ export function overrideHeldItems(scene: BattleScene, pokemon: Pokemon, isPlayer
return;
}
if (!isPlayer) {
scene.clearEnemyHeldItemModifiers();
}
heldItemsOverride.forEach(item => {
const modifierFunc = modifierTypes[item.name];
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 ErrorInterceptor from "#app/test/utils/errorInterceptor";
import InputsHandler from "#app/test/utils/inputsHandler";
import { MockClock } from "#app/test/utils/mocks/mockClock";
import CommandUiHandler from "#app/ui/command-ui-handler";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import PartyUiHandler from "#app/ui/party-ui-handler";
@ -360,12 +359,10 @@ export default class GameManager {
}
async killPokemon(pokemon: PlayerPokemon | EnemyPokemon) {
(this.scene.time as MockClock).overrideDelay = 0.01;
return new Promise<void>(async (resolve, reject) => {
pokemon.hp = 0;
this.scene.pushPhase(new FaintPhase(this.scene, pokemon.getBattlerIndex(), true));
await this.phaseInterceptor.to(FaintPhase).catch((e) => reject(e));
(this.scene.time as MockClock).overrideDelay = undefined;
resolve();
});
}

View File

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

View File

@ -2,23 +2,22 @@ import Clock = Phaser.Time.Clock;
export class MockClock extends Clock {
public overrideDelay: number | undefined;
public overrideDelay: number | null = 1;
constructor(scene) {
super(scene);
this.overrideDelay = undefined;
setInterval(() => {
/*
To simulate frame update
eventEmitter.on(SceneEvents.PRE_UPDATE, this.preUpdate, this);
eventEmitter.on(SceneEvents.UPDATE, this.update, this);
*/
this.preUpdate(this.systems.game.loop.time, 100);
this.update(this.systems.game.loop.time, 100);
}, 100);
this.preUpdate(this.systems.game.loop.time, 1);
this.update(this.systems.game.loop.time, 1);
}, 1);
}
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);
}
}