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

View File

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