mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-21 17:12:44 +02:00
Simplify game-speed.ts and update evo phase
This commit is contained in:
parent
9a601b80a2
commit
f49c4e7a42
@ -23,6 +23,8 @@ export class EvolutionPhase extends Phase {
|
|||||||
protected pokemon: PlayerPokemon;
|
protected pokemon: PlayerPokemon;
|
||||||
protected lastLevel: number;
|
protected lastLevel: number;
|
||||||
|
|
||||||
|
protected evoChain: Phaser.Tweens.TweenChain | null = null;
|
||||||
|
|
||||||
private preEvolvedPokemonName: string;
|
private preEvolvedPokemonName: string;
|
||||||
|
|
||||||
private evolution: SpeciesFormEvolution | null;
|
private evolution: SpeciesFormEvolution | null;
|
||||||
@ -116,7 +118,7 @@ export class EvolutionPhase extends Phase {
|
|||||||
* @returns The sprite object that was passed in
|
* @returns The sprite object that was passed in
|
||||||
*/
|
*/
|
||||||
protected 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 = pokemon.getSpriteKey(true);
|
||||||
try {
|
try {
|
||||||
sprite.play(spriteKey);
|
sprite.play(spriteKey);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
@ -264,11 +266,11 @@ export class EvolutionPhase extends Phase {
|
|||||||
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 = this.canCancel;
|
this.evolutionHandler.canCancel = this.canCancel;
|
||||||
this.doCycle(1).then(success => {
|
this.doCycle(1, undefined, () => {
|
||||||
if (success) {
|
if (this.evolutionHandler.cancelled) {
|
||||||
this.handleSuccessEvolution(evolvedPokemon);
|
|
||||||
} else {
|
|
||||||
this.handleFailedEvolution(evolvedPokemon);
|
this.handleFailedEvolution(evolvedPokemon);
|
||||||
|
} else {
|
||||||
|
this.handleSuccessEvolution(evolvedPokemon);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -474,7 +476,6 @@ export class EvolutionPhase extends Phase {
|
|||||||
|
|
||||||
doSpiralUpward() {
|
doSpiralUpward() {
|
||||||
let f = 0;
|
let f = 0;
|
||||||
|
|
||||||
globalScene.tweens.addCounter({
|
globalScene.tweens.addCounter({
|
||||||
repeat: 64,
|
repeat: 64,
|
||||||
duration: getFrameMs(1),
|
duration: getFrameMs(1),
|
||||||
@ -513,36 +514,38 @@ export class EvolutionPhase extends Phase {
|
|||||||
/**
|
/**
|
||||||
* Return a tween chain that cycles the evolution sprites
|
* Return a tween chain that cycles the evolution sprites
|
||||||
*/
|
*/
|
||||||
doCycle(cycles: number, lastCycle = 15): Promise<boolean> {
|
doCycle(cycles: number, lastCycle = 15, onComplete = () => {}): void {
|
||||||
return new Promise(resolve => {
|
// Make our tween start both at the same time
|
||||||
const isLastCycle = cycles === lastCycle;
|
const tweens: Phaser.Types.Tweens.TweenBuilderConfig[] = [];
|
||||||
globalScene.tweens.addMultiple([
|
for (let i = cycles; i <= lastCycle; i += 0.5) {
|
||||||
{
|
tweens.push({
|
||||||
targets: this.pokemonTintSprite,
|
targets: [this.pokemonTintSprite, this.pokemonEvoTintSprite],
|
||||||
scale: 0.25,
|
scale: (_target, _key, _value, targetIndex: number, _totalTargets, _tween) => (targetIndex === 0 ? 0.25 : 1),
|
||||||
ease: "Cubic.easeInOut",
|
ease: "Cubic.easeInOut",
|
||||||
duration: 500 / cycles,
|
duration: 500 / i,
|
||||||
yoyo: !isLastCycle,
|
yoyo: i !== lastCycle,
|
||||||
},
|
|
||||||
{
|
|
||||||
targets: this.pokemonEvoTintSprite,
|
|
||||||
scale: 1,
|
|
||||||
ease: "Cubic.easeInOut",
|
|
||||||
duration: 500 / cycles,
|
|
||||||
yoyo: !isLastCycle,
|
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
if (this.evolutionHandler.cancelled) {
|
if (this.evolutionHandler.cancelled) {
|
||||||
return resolve(false);
|
// cause the tween chain to complete instantly, skipping the remaining tweens.
|
||||||
|
this.pokemonEvoTintSprite.setScale(1);
|
||||||
|
this.pokemonEvoTintSprite.setVisible(false);
|
||||||
|
this.evoChain?.complete?.();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (cycles < lastCycle) {
|
if (i === lastCycle) {
|
||||||
this.doCycle(cycles + 0.5, lastCycle).then(success => resolve(success));
|
this.pokemonEvoTintSprite.setScale(1);
|
||||||
} else {
|
|
||||||
this.pokemonTintSprite.setVisible(false);
|
|
||||||
resolve(true);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.evoChain = globalScene.tweens.chain({
|
||||||
|
targets: null,
|
||||||
|
tweens,
|
||||||
|
onComplete: () => {
|
||||||
|
this.evoChain = null;
|
||||||
|
onComplete();
|
||||||
},
|
},
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { globalScene } from "#app/global-scene";
|
import { globalScene } from "#app/global-scene";
|
||||||
import { FixedInt, fixedInt } from "#app/utils/common";
|
import { fixedInt } from "#app/utils/common";
|
||||||
import { achvs } from "../system/achv";
|
import { achvs } from "../system/achv";
|
||||||
import type { SpeciesFormChange } from "../data/pokemon-forms";
|
import type { SpeciesFormChange } from "../data/pokemon-forms";
|
||||||
import { getSpeciesFormChangeMessage } from "#app/data/pokemon-forms/form-change-triggers";
|
import { getSpeciesFormChangeMessage } from "#app/data/pokemon-forms/form-change-triggers";
|
||||||
@ -146,7 +146,7 @@ export class FormChangePhase extends EvolutionPhase {
|
|||||||
targets: this.evolutionBgOverlay,
|
targets: this.evolutionBgOverlay,
|
||||||
alpha: 0,
|
alpha: 0,
|
||||||
duration: 250,
|
duration: 250,
|
||||||
delay: fixedInt(1000),
|
delay: 1000,
|
||||||
});
|
});
|
||||||
this.evolutionBg.setVisible(true).play();
|
this.evolutionBg.setVisible(true).play();
|
||||||
},
|
},
|
||||||
@ -167,13 +167,13 @@ export class FormChangePhase extends EvolutionPhase {
|
|||||||
],
|
],
|
||||||
|
|
||||||
// Step 3: Commence the form change animation via doCycle then continue the animation chain with afterCycle
|
// Step 3: Commence the form change animation via doCycle then continue the animation chain with afterCycle
|
||||||
completeDelay: new FixedInt(1100),
|
completeDelay: 1100,
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
globalScene.playSound("se/beam");
|
globalScene.playSound("se/beam");
|
||||||
this.doArcDownward();
|
this.doArcDownward();
|
||||||
globalScene.time.delayedCall(1000, () => {
|
globalScene.time.delayedCall(1000, () => {
|
||||||
this.pokemonEvoTintSprite.setScale(0.25).setVisible(true);
|
this.pokemonEvoTintSprite.setScale(0.25).setVisible(true);
|
||||||
this.doCycle(1, 1).then(() => this.afterCycle(preName, transformedPokemon));
|
this.doCycle(1, 1, () => this.afterCycle(preName, transformedPokemon));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -5,9 +5,13 @@ import type BattleScene from "#app/battle-scene";
|
|||||||
import { globalScene } from "#app/global-scene";
|
import { globalScene } from "#app/global-scene";
|
||||||
import { FixedInt } from "#app/utils/common";
|
import { FixedInt } from "#app/utils/common";
|
||||||
|
|
||||||
|
type TweenManager = typeof Phaser.Tweens.TweenManager.prototype;
|
||||||
|
|
||||||
|
/** The set of properties to mutate */
|
||||||
|
const PROPERTIES = ["delay", "completeDelay", "loopDelay", "duration", "repeatDelay", "hold", "startDelay"];
|
||||||
|
|
||||||
type FadeInType = typeof FadeIn;
|
type FadeInType = typeof FadeIn;
|
||||||
type FadeOutType = typeof FadeOut;
|
type FadeOutType = typeof FadeOut;
|
||||||
|
|
||||||
export function initGameSpeed() {
|
export function initGameSpeed() {
|
||||||
const thisArg = this as BattleScene;
|
const thisArg = this as BattleScene;
|
||||||
|
|
||||||
@ -18,16 +22,44 @@ export function initGameSpeed() {
|
|||||||
return thisArg.gameSpeed === 1 ? value : Math.ceil((value /= thisArg.gameSpeed));
|
return thisArg.gameSpeed === 1 ? value : Math.ceil((value /= thisArg.gameSpeed));
|
||||||
};
|
};
|
||||||
|
|
||||||
const originalAddEvent = this.time.addEvent;
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Complexity is necessary here
|
||||||
|
const mutateProperties = (obj: any, allowArray = false) => {
|
||||||
|
// We do not mutate Tweens or TweenChains
|
||||||
|
if (obj instanceof Phaser.Tweens.Tween || obj instanceof Phaser.Tweens.TweenChain) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If allowArray is true then check if first obj is an array and if so, mutate the tweens inside
|
||||||
|
if (allowArray && Array.isArray(obj)) {
|
||||||
|
for (const tween of obj) {
|
||||||
|
mutateProperties(tween);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const prop of PROPERTIES) {
|
||||||
|
const objProp = obj[prop];
|
||||||
|
if (typeof objProp === "number" || objProp instanceof FixedInt) {
|
||||||
|
obj[prop] = transformValue(objProp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If the object has a 'tweens' property, then it is a tween chain
|
||||||
|
// and we need to mutate its properties as well
|
||||||
|
if (obj.tweens) {
|
||||||
|
for (const tween of obj.tweens) {
|
||||||
|
mutateProperties(tween);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalAddEvent: typeof Phaser.Time.Clock.prototype.addEvent = this.time.addEvent;
|
||||||
this.time.addEvent = function (config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig) {
|
this.time.addEvent = function (config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig) {
|
||||||
if (!(config instanceof Phaser.Time.TimerEvent) && config.delay) {
|
if (!(config instanceof Phaser.Time.TimerEvent) && config.delay) {
|
||||||
config.delay = transformValue(config.delay);
|
config.delay = transformValue(config.delay);
|
||||||
}
|
}
|
||||||
return originalAddEvent.apply(this, [config]);
|
return originalAddEvent.apply(this, [config]);
|
||||||
};
|
};
|
||||||
const originalTweensAdd = this.tweens.add;
|
const originalTweensAdd: TweenManager["add"] = 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
|
||||||
@ -35,82 +67,33 @@ export function initGameSpeed() {
|
|||||||
| Phaser.Tweens.Tween
|
| Phaser.Tweens.Tween
|
||||||
| Phaser.Tweens.TweenChain,
|
| Phaser.Tweens.TweenChain,
|
||||||
) {
|
) {
|
||||||
if (config.completeDelay) {
|
mutateProperties(config);
|
||||||
config.completeDelay = transformValue(config.completeDelay as number | FixedInt);
|
|
||||||
}
|
|
||||||
if (config.loopDelay) {
|
|
||||||
config.loopDelay = transformValue(config.loopDelay as number | FixedInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(config instanceof Phaser.Tweens.TweenChain)) {
|
|
||||||
if (config.duration) {
|
|
||||||
config.duration = transformValue(config.duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(config instanceof Phaser.Tweens.Tween)) {
|
|
||||||
if (config.delay) {
|
|
||||||
config.delay = transformValue(config.delay as number | FixedInt);
|
|
||||||
}
|
|
||||||
if (config.repeatDelay) {
|
|
||||||
config.repeatDelay = transformValue(config.repeatDelay);
|
|
||||||
}
|
|
||||||
if (config.hold) {
|
|
||||||
config.hold = transformValue(config.hold);
|
|
||||||
}
|
|
||||||
1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return originalTweensAdd.apply(this, [config]);
|
return originalTweensAdd.apply(this, [config]);
|
||||||
};
|
} as typeof originalTweensAdd;
|
||||||
const originalTweensChain = this.tweens.chain;
|
|
||||||
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: This isn't bad
|
const originalTweensChain: TweenManager["chain"] = this.tweens.chain;
|
||||||
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) {
|
mutateProperties(config);
|
||||||
for (const t of config.tweens) {
|
|
||||||
if (t.duration) {
|
|
||||||
t.duration = transformValue(t.duration);
|
|
||||||
}
|
|
||||||
if (t.delay) {
|
|
||||||
t.delay = transformValue(t.delay);
|
|
||||||
}
|
|
||||||
if (t.repeatDelay) {
|
|
||||||
t.repeatDelay = transformValue(t.repeatDelay);
|
|
||||||
}
|
|
||||||
if (t.loopDelay) {
|
|
||||||
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]);
|
return originalTweensChain.apply(this, [config]);
|
||||||
};
|
} as typeof originalTweensChain;
|
||||||
const originalAddCounter = this.tweens.addCounter;
|
const originalAddCounter: TweenManager["addCounter"] = this.tweens.addCounter;
|
||||||
|
|
||||||
this.tweens.addCounter = function (config: Phaser.Types.Tweens.NumberTweenBuilderConfig) {
|
this.tweens.addCounter = function (config: Phaser.Types.Tweens.NumberTweenBuilderConfig) {
|
||||||
if (config.duration) {
|
mutateProperties(config);
|
||||||
config.duration = transformValue(config.duration);
|
|
||||||
}
|
|
||||||
if (config.delay) {
|
|
||||||
config.delay = transformValue(config.delay);
|
|
||||||
}
|
|
||||||
if (config.repeatDelay) {
|
|
||||||
config.repeatDelay = transformValue(config.repeatDelay);
|
|
||||||
}
|
|
||||||
if (config.loopDelay) {
|
|
||||||
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]);
|
return originalAddCounter.apply(this, [config]);
|
||||||
};
|
} as typeof originalAddCounter;
|
||||||
|
|
||||||
|
// const originalCreate: TweenManager["create"] = this.tweens.create;
|
||||||
|
// this.tweens.create = function (config: Phaser.Types.Tweens.TweenBuilderConfig) {
|
||||||
|
// mutateProperties(config, true);
|
||||||
|
// return originalCreate.apply(this, [config]);
|
||||||
|
// } as typeof originalCreate;
|
||||||
|
|
||||||
|
const originalAddMultiple: TweenManager["addMultiple"] = this.tweens.addMultiple;
|
||||||
|
this.tweens.addMultiple = function (config: Phaser.Types.Tweens.TweenBuilderConfig[]) {
|
||||||
|
mutateProperties(config, true);
|
||||||
|
return originalAddMultiple.apply(this, [config]);
|
||||||
|
} as typeof originalAddMultiple;
|
||||||
|
|
||||||
const originalFadeOut = SoundFade.fadeOut;
|
const originalFadeOut = SoundFade.fadeOut;
|
||||||
SoundFade.fadeOut = ((_scene: Phaser.Scene, sound: Phaser.Sound.BaseSound, duration: number, destroy?: boolean) =>
|
SoundFade.fadeOut = ((_scene: Phaser.Scene, sound: Phaser.Sound.BaseSound, duration: number, destroy?: boolean) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user