[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:
parent
5f918ca001
commit
5f9bd21a51
|
@ -21,7 +21,7 @@ import Overrides from "#app/overrides";
|
|||
import { ModifierType, modifierTypes } from "./modifier-type";
|
||||
import { Command } from "#app/ui/command-ui-handler";
|
||||
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 { allMoves } from "#app/data/move";
|
||||
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue