mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-05 07:52:17 +02:00
Move sorting to BattleScene
This commit is contained in:
parent
80ac3d964c
commit
5f4daa2ef4
@ -2879,6 +2879,25 @@ export default class BattleScene extends SceneBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the first consecutive set of occurences of {@linkcode targetPhase} in {@linkcode phaseQueue}
|
||||||
|
* @param targetPhase The type of phase to search for and sort
|
||||||
|
* @param by A function to compare the phases with
|
||||||
|
* @see {@linkcode Array.sort} for the comparison function
|
||||||
|
*/
|
||||||
|
sortPhaseType(targetPhase: Constructor<Phase>, by: (a: Phase, b: Phase) => number): void {
|
||||||
|
const startIndex = this.phaseQueue.findIndex(phase => phase instanceof targetPhase);
|
||||||
|
if (startIndex === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const endIndex = this.phaseQueue.findIndex((phase, index) => index > startIndex && !(phase instanceof targetPhase));
|
||||||
|
|
||||||
|
const sortedSubset = this.phaseQueue
|
||||||
|
.slice(startIndex, endIndex !== -1 ? endIndex + 1 : this.phaseQueue.length)
|
||||||
|
.sort(by);
|
||||||
|
this.phaseQueue.splice(startIndex, sortedSubset.length, ...sortedSubset);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a MessagePhase, either to PhaseQueuePrepend or nextCommandPhaseQueue
|
* Adds a MessagePhase, either to PhaseQueuePrepend or nextCommandPhaseQueue
|
||||||
* @param message string for MessagePhase
|
* @param message string for MessagePhase
|
||||||
|
@ -64,7 +64,8 @@ export class PostSummonPhase extends PokemonPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private orderPostSummonPhases() {
|
private orderPostSummonPhases() {
|
||||||
globalScene.phaseQueue.sort(
|
globalScene.sortPhaseType(
|
||||||
|
PostSummonPhase,
|
||||||
(phaseA: PostSummonPhase, phaseB: PostSummonPhase) =>
|
(phaseA: PostSummonPhase, phaseB: PostSummonPhase) =>
|
||||||
phaseB.getPokemon().getEffectiveStat(Stat.SPD) - phaseA.getPokemon().getEffectiveStat(Stat.SPD),
|
phaseB.getPokemon().getEffectiveStat(Stat.SPD) - phaseA.getPokemon().getEffectiveStat(Stat.SPD),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user