Update evolution phase and types

This commit is contained in:
Sirz Benjie 2025-04-29 23:34:44 -05:00
parent 8f6dc78608
commit 75511354ee
No known key found for this signature in database
GPG Key ID: 38AC42D68CF5E138
2 changed files with 52 additions and 34 deletions

View File

@ -49,7 +49,7 @@ export class EvolutionPhase extends Phase {
* @param lastLevel - The level at which the Pokemon is evolving
* @param canCancel - Whether the evolution can be cancelled by the player
*/
constructor(pokemon: PlayerPokemon, evolution: SpeciesFormEvolution | null, lastLevel: number, canCancel = false) {
constructor(pokemon: PlayerPokemon, evolution: SpeciesFormEvolution | null, lastLevel: number, canCancel = true) {
super();
this.pokemon = pokemon;
@ -115,7 +115,7 @@ export class EvolutionPhase extends Phase {
*
* @returns The sprite object that was passed in
*/
private configureSprite(pokemon: Pokemon, sprite: Phaser.GameObjects.Sprite, setPipeline = true): typeof sprite {
protected configureSprite(pokemon: Pokemon, sprite: Phaser.GameObjects.Sprite, setPipeline = true): typeof sprite {
const spriteKey = this.pokemon.getSpriteKey(true);
try {
sprite.play(spriteKey);
@ -263,7 +263,7 @@ export class EvolutionPhase extends Phase {
private prepareForCycle(evolvedPokemon: Pokemon): void {
globalScene.time.delayedCall(1500, () => {
this.pokemonEvoTintSprite.setScale(0.25).setVisible(true);
this.evolutionHandler.canCancel = true;
this.evolutionHandler.canCancel = this.canCancel;
this.doCycle(1).then(success => {
if (success) {
this.handleSuccessEvolution(evolvedPokemon);
@ -510,34 +510,39 @@ export class EvolutionPhase extends Phase {
});
}
doCycle(l: number, lastCycle = 15): Promise<boolean> {
/**
* Return a tween chain that cycles the evolution sprites
*/
doCycle(cycles: number, lastCycle = 15): Promise<boolean> {
return new Promise(resolve => {
const isLastCycle = l === lastCycle;
globalScene.tweens.add({
targets: this.pokemonTintSprite,
scale: 0.25,
ease: "Cubic.easeInOut",
duration: 500 / l,
yoyo: !isLastCycle,
});
globalScene.tweens.add({
targets: this.pokemonEvoTintSprite,
scale: 1,
ease: "Cubic.easeInOut",
duration: 500 / l,
yoyo: !isLastCycle,
onComplete: () => {
if (this.evolutionHandler.cancelled) {
return resolve(false);
}
if (l < lastCycle) {
this.doCycle(l + 0.5, lastCycle).then(success => resolve(success));
} else {
this.pokemonTintSprite.setVisible(false);
resolve(true);
}
const isLastCycle = cycles === lastCycle;
globalScene.tweens.addMultiple([
{
targets: this.pokemonTintSprite,
scale: 0.25,
ease: "Cubic.easeInOut",
duration: 500 / cycles,
yoyo: !isLastCycle,
},
});
{
targets: this.pokemonEvoTintSprite,
scale: 1,
ease: "Cubic.easeInOut",
duration: 500 / cycles,
yoyo: !isLastCycle,
onComplete: () => {
if (this.evolutionHandler.cancelled) {
return resolve(false);
}
if (cycles < lastCycle) {
this.doCycle(cycles + 0.5, lastCycle).then(success => resolve(success));
} else {
this.pokemonTintSprite.setVisible(false);
resolve(true);
}
},
},
]);
});
}

View File

@ -26,6 +26,8 @@ export function initGameSpeed() {
return originalAddEvent.apply(this, [config]);
};
const originalTweensAdd = this.tweens.add;
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: This isn't bad
this.tweens.add = function (
config:
| Phaser.Types.Tweens.TweenBuilderConfig
@ -33,8 +35,11 @@ export function initGameSpeed() {
| Phaser.Tweens.Tween
| Phaser.Tweens.TweenChain,
) {
if (config.completeDelay) {
config.completeDelay = transformValue(config.completeDelay as number | FixedInt);
}
if (config.loopDelay) {
config.loopDelay = transformValue(config.loopDelay as number);
config.loopDelay = transformValue(config.loopDelay as number | FixedInt);
}
if (!(config instanceof Phaser.Tweens.TweenChain)) {
@ -44,7 +49,7 @@ export function initGameSpeed() {
if (!(config instanceof Phaser.Tweens.Tween)) {
if (config.delay) {
config.delay = transformValue(config.delay as number);
config.delay = transformValue(config.delay as number | FixedInt);
}
if (config.repeatDelay) {
config.repeatDelay = transformValue(config.repeatDelay);
@ -52,11 +57,13 @@ export function initGameSpeed() {
if (config.hold) {
config.hold = transformValue(config.hold);
}
1;
}
}
return originalTweensAdd.apply(this, [config]);
};
const originalTweensChain = this.tweens.chain;
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: This isn't bad
this.tweens.chain = function (config: Phaser.Types.Tweens.TweenChainBuilderConfig): Phaser.Tweens.TweenChain {
if (config.tweens) {
for (const t of config.tweens) {
@ -64,17 +71,20 @@ export function initGameSpeed() {
t.duration = transformValue(t.duration);
}
if (t.delay) {
t.delay = transformValue(t.delay as number);
t.delay = transformValue(t.delay);
}
if (t.repeatDelay) {
t.repeatDelay = transformValue(t.repeatDelay);
}
if (t.loopDelay) {
t.loopDelay = transformValue(t.loopDelay as number);
t.loopDelay = transformValue(t.loopDelay);
}
if (t.hold) {
t.hold = transformValue(t.hold);
}
if (t.completeDelay) {
t.completeDelay = transformValue(t.completeDelay);
}
}
}
return originalTweensChain.apply(this, [config]);
@ -91,11 +101,14 @@ export function initGameSpeed() {
config.repeatDelay = transformValue(config.repeatDelay);
}
if (config.loopDelay) {
config.loopDelay = transformValue(config.loopDelay as number);
config.loopDelay = transformValue(config.loopDelay);
}
if (config.hold) {
config.hold = transformValue(config.hold);
}
if (config.completeDelay) {
config.completeDelay = transformValue(config.completeDelay as number | FixedInt);
}
return originalAddCounter.apply(this, [config]);
};