From 824b7513217bb4b1c97c7a1f179522a1a81a30cc Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 20 Feb 2024 00:24:39 -0500 Subject: [PATCH] Add skip for egg hatch animation --- src/egg-hatch-phase.ts | 152 ++++++++++++++++++------------ src/ui/egg-hatch-scene-handler.ts | 7 ++ 2 files changed, 99 insertions(+), 60 deletions(-) diff --git a/src/egg-hatch-phase.ts b/src/egg-hatch-phase.ts index 927e950370e..4f27a1a4065 100644 --- a/src/egg-hatch-phase.ts +++ b/src/egg-hatch-phase.ts @@ -32,6 +32,11 @@ export class EggHatchPhase extends BattlePhase { private infoContainer: Phaser.GameObjects.Container; private statsContainer: StatsContainer; + private pokemon: PlayerPokemon; + private canSkip: boolean; + private skipped: boolean; + private evolutionBgm: AnySound; + constructor(scene: BattleScene, egg: Egg) { super(scene); @@ -153,84 +158,41 @@ export class EggHatchPhase extends BattlePhase { this.pokemonSprite.setVisible(false); - let evolutionBgm: AnySound; + this.pokemon = pokemon; pokemon.loadAssets().then(() => { - this.scene.time.delayedCall(1000, () => evolutionBgm = this.scene.playSoundWithoutBgm('evolution')); + this.scene.time.delayedCall(1000, () => { + this.evolutionBgm = this.scene.playSoundWithoutBgm('evolution'); + this.canSkip = true; + }); this.scene.time.delayedCall(2000, () => { + if (this.skipped) + return; this.eggCrackSprite.setVisible(true); this.doSpray(1, this.eggSprite.displayHeight / -2); this.doEggShake(2).then(() => { + if (this.skipped) + return; this.scene.time.delayedCall(1000, () => { + if (this.skipped) + return; this.doSpray(2, this.eggSprite.displayHeight / -4); this.eggCrackSprite.setFrame('1'); this.scene.time.delayedCall(125, () => this.eggCrackSprite.setFrame('2')); this.doEggShake(4).then(() => { + if (this.skipped) + return; this.scene.time.delayedCall(1000, () => { + if (this.skipped) + return; this.scene.playSound('egg_crack'); this.doSpray(4); this.eggCrackSprite.setFrame('3'); this.scene.time.delayedCall(125, () => this.eggCrackSprite.setFrame('4')); this.doEggShake(8, 2).then(() => { - SoundFade.fadeOut(this.scene, evolutionBgm, Utils.fixedInt(100)); - for (let e = 0; e < 5; e++) - this.scene.time.delayedCall(Utils.fixedInt(375 * e), () => this.scene.playSound('egg_hatch', { volume: 1 - (e * 0.2) })); - this.eggLightraysOverlay.setVisible(true); - this.eggLightraysOverlay.play('egg_lightrays'); - this.scene.tweens.add({ - duration: Utils.fixedInt(125), - targets: this.eggHatchOverlay, - alpha: 1, - ease: 'Cubic.easeIn' - }); - this.scene.time.delayedCall(Utils.fixedInt(1500), () => { - const isShiny = pokemon.isShiny(); - if (pokemon.species.mythical) - this.scene.validateAchv(achvs.HATCH_MYTHICAL); - if (pokemon.species.legendary) - this.scene.validateAchv(achvs.HATCH_LEGENDARY); - if (isShiny) - this.scene.validateAchv(achvs.HATCH_SHINY); - this.eggContainer.setVisible(false); - this.pokemonSprite.play(pokemon.getSpriteKey(true)); - this.pokemonSprite.pipelineData['ignoreTimeTint'] = true; - this.pokemonSprite.setVisible(true); - this.scene.time.delayedCall(Utils.fixedInt(1000), () => { - pokemon.cry(); - if (isShiny) { - this.scene.time.delayedCall(Utils.fixedInt(1250), () => { - this.pokemonShinySparkle.play('sparkle'); - this.scene.playSound('sparkle'); - }); - } - this.scene.time.delayedCall(Utils.fixedInt(!isShiny ? 1250 : 1750), () => { - this.scene.tweens.add({ - targets: this.infoContainer, - duration: Utils.fixedInt(750), - ease: 'Cubic.easeInOut', - x: this.eggHatchBg.displayWidth - 52 - }); - - this.scene.playSoundWithoutBgm('evolution_fanfare'); - - this.scene.ui.showText(`${pokemon.name} hatched from the egg!`, null, () => { - this.scene.gameData.updateSpeciesDexIvs(pokemon.species.speciesId, pokemon.ivs); - this.scene.gameData.setPokemonCaught(pokemon, true, true).then(() => { - this.scene.ui.showText(null, 0); - this.end(); - }); - }, null, true, 3000); - //this.scene.time.delayedCall(Utils.fixedInt(4250), () => this.scene.playBgm()); - }); - }); - this.scene.tweens.add({ - duration: Utils.fixedInt(3000), - targets: this.eggHatchOverlay, - alpha: 0, - ease: 'Cubic.easeOut' - }); - }); + if (!this.skipped) + this.doHatch(); }); }); }); @@ -277,6 +239,76 @@ export class EggHatchPhase extends BattlePhase { }); } + trySkip(): boolean { + if (!this.canSkip || this.skipped) + return false; + this.skipped = true; + this.doHatch(); + return true; + } + + doHatch(): void { + this.canSkip = false; + SoundFade.fadeOut(this.scene, this.evolutionBgm, Utils.fixedInt(100)); + for (let e = 0; e < 5; e++) + this.scene.time.delayedCall(Utils.fixedInt(375 * e), () => this.scene.playSound('egg_hatch', { volume: 1 - (e * 0.2) })); + this.eggLightraysOverlay.setVisible(true); + this.eggLightraysOverlay.play('egg_lightrays'); + this.scene.tweens.add({ + duration: Utils.fixedInt(125), + targets: this.eggHatchOverlay, + alpha: 1, + ease: 'Cubic.easeIn' + }); + this.scene.time.delayedCall(Utils.fixedInt(1500), () => { + const isShiny = this.pokemon.isShiny(); + if (this.pokemon.species.mythical) + this.scene.validateAchv(achvs.HATCH_MYTHICAL); + if (this.pokemon.species.legendary) + this.scene.validateAchv(achvs.HATCH_LEGENDARY); + if (isShiny) + this.scene.validateAchv(achvs.HATCH_SHINY); + this.eggContainer.setVisible(false); + this.pokemonSprite.play(this.pokemon.getSpriteKey(true)); + this.pokemonSprite.pipelineData['ignoreTimeTint'] = true; + this.pokemonSprite.setVisible(true); + this.scene.time.delayedCall(Utils.fixedInt(1000), () => { + this.pokemon.cry(); + if (isShiny) { + this.scene.time.delayedCall(Utils.fixedInt(1250), () => { + this.pokemonShinySparkle.play('sparkle'); + this.scene.playSound('sparkle'); + }); + } + this.scene.time.delayedCall(Utils.fixedInt(!isShiny ? 1250 : 1750), () => { + this.scene.tweens.add({ + targets: this.infoContainer, + duration: Utils.fixedInt(750), + ease: 'Cubic.easeInOut', + x: this.eggHatchBg.displayWidth - 52 + }); + + this.scene.playSoundWithoutBgm('evolution_fanfare'); + + this.scene.ui.showText(`${this.pokemon.name} hatched from the egg!`, null, () => { + this.scene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); + this.scene.gameData.setPokemonCaught(this.pokemon, true, true).then(() => { + this.scene.ui.showText(null, 0); + this.end(); + }); + }, null, true, 3000); + //this.scene.time.delayedCall(Utils.fixedInt(4250), () => this.scene.playBgm()); + }); + }); + this.scene.tweens.add({ + duration: Utils.fixedInt(3000), + targets: this.eggHatchOverlay, + alpha: 0, + ease: 'Cubic.easeOut' + }); + }); + } + sin(index: integer, amplitude: integer): number { return amplitude * Math.sin(index * (Math.PI / 128)); } diff --git a/src/ui/egg-hatch-scene-handler.ts b/src/ui/egg-hatch-scene-handler.ts index e4801b9e1c4..2d58054e999 100644 --- a/src/ui/egg-hatch-scene-handler.ts +++ b/src/ui/egg-hatch-scene-handler.ts @@ -1,4 +1,5 @@ import BattleScene, { Button } from "../battle-scene"; +import { EggHatchPhase } from "../egg-hatch-phase"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; @@ -30,6 +31,12 @@ export default class EggHatchSceneHandler extends UiHandler { } processInput(button: Button): boolean { + if (button === Button.ACTION || button === Button.CANCEL) { + const phase = this.scene.getCurrentPhase() as EggHatchPhase; + if (phase.trySkip()) + return true; + } + return this.scene.ui.getMessageHandler().processInput(button); }