From 00f7bc595b04fbd92817a98f154a6b5e2c35c102 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Mon, 23 Oct 2023 09:00:23 -0400 Subject: [PATCH] Fix biome selection causing bgm-related crash --- src/battle-phases.ts | 4 ++-- src/battle-scene.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 077a2a8040a..b98ca6825c7 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -453,13 +453,13 @@ export class SelectBiomePhase extends BattlePhase { start() { super.start(); - this.scene.fadeOutBgm(2000, true); - const currentBiome = this.scene.arena.biomeType; const setNextBiome = (nextBiome: Biome) => { if (this.scene.gameMode === GameMode.CLASSIC) this.scene.unshiftPhase(new PartyHealPhase(this.scene, false)); + else + this.scene.fadeOutBgm(2000, true); this.scene.unshiftPhase(new SwitchBiomePhase(this.scene, nextBiome)); this.end(); }; diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 4e33e72c1b5..34dc3aabad9 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -867,11 +867,11 @@ export default class BattleScene extends Phaser.Scene { playNewBgm(); }); if (fadeOut) { - this.fadeOutBgm(500, true); - this.time.delayedCall(750, () => { + const onBgmFaded = () => { if (loaded && (!this.bgm.isPlaying || this.bgm.pendingRemove)) playNewBgm(); - }); + }; + this.time.delayedCall(this.fadeOutBgm(500, true) ? 750 : 250, onBgmFaded); } if (!this.load.isLoading()) this.load.start(); @@ -887,7 +887,7 @@ export default class BattleScene extends Phaser.Scene { this.bgm.resume(); } - fadeOutBgm(duration?: integer, destroy?: boolean): void { + fadeOutBgm(duration?: integer, destroy?: boolean): boolean { if (!this.bgm) return; if (!duration) @@ -895,7 +895,12 @@ export default class BattleScene extends Phaser.Scene { if (destroy === undefined) destroy = true; const bgm = this.sound.get(this.bgm.key); - SoundFade.fadeOut(this, bgm, duration, destroy); + if (bgm) { + SoundFade.fadeOut(this, bgm, duration, destroy); + return true; + } + + return false; } playSound(soundName: string, config?: object) {