pokerogue/src/phases/move-anim-test-phase.ts
NightKev 0107b1d47e
[Refactor] Create global scene variable (#4766)
* Replace various `scene` pass-arounds with global scene variable

* Modify tests

* Add scene back to `fade[in|out]()` calls

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

* Fix Bug Superfan ME test

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

* Re-enable fixed test

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>

* Rename `gScene` to `globalScene`

* Move `globalScene` to its own file to fix import/async issues

* Fix `SelectModifierPhase` tests

* Fix ME tests by removing `scene` from `expect()`s

* Resolve merge issues

* Remove tsdocs referencing `scene` params

Remove missed instances of `.scene`

* Remove unnecessary `globalScene` usage in `loading-scene.ts`

* Fix merge conflicts

* Attempt to fix circular import issue

* Found the source of the import issue

* Fix merge issues

---------

Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
2025-01-12 15:33:05 -08:00

47 lines
1.6 KiB
TypeScript

import { globalScene } from "#app/global-scene";
import { initMoveAnim, loadMoveAnimAssets, MoveAnim } from "#app/data/battle-anims";
import { allMoves, SelfStatusMove } from "#app/data/move";
import { Moves } from "#app/enums/moves";
import * as Utils from "#app/utils";
import { BattlePhase } from "./battle-phase";
export class MoveAnimTestPhase extends BattlePhase {
private moveQueue: Moves[];
constructor(moveQueue?: Moves[]) {
super();
this.moveQueue = moveQueue || Utils.getEnumValues(Moves).slice(1);
}
start() {
const moveQueue = this.moveQueue.slice(0);
this.playMoveAnim(moveQueue, true);
}
playMoveAnim(moveQueue: Moves[], player: boolean) {
const moveId = player ? moveQueue[0] : moveQueue.shift();
if (moveId === undefined) {
this.playMoveAnim(this.moveQueue.slice(0), true);
return;
} else if (player) {
console.log(Moves[moveId]);
}
initMoveAnim(moveId).then(() => {
loadMoveAnimAssets([ moveId ], true)
.then(() => {
const user = player ? globalScene.getPlayerPokemon()! : globalScene.getEnemyPokemon()!;
const target = (player !== (allMoves[moveId] instanceof SelfStatusMove)) ? globalScene.getEnemyPokemon()! : globalScene.getPlayerPokemon()!;
new MoveAnim(moveId, user, target.getBattlerIndex()).play(allMoves[moveId].hitsSubstitute(user, target), () => { // TODO: are the bangs correct here?
if (player) {
this.playMoveAnim(moveQueue, false);
} else {
this.playMoveAnim(moveQueue, true);
}
});
});
});
}
}