diff --git a/src/default-assets.ts b/src/default-assets.ts new file mode 100644 index 00000000000..007398de5c5 --- /dev/null +++ b/src/default-assets.ts @@ -0,0 +1,61 @@ + +export const allDefaultBgmAssets: Map = new Map([ + ["menu", undefined], + ["level_up_fanfare", "bw/level_up_fanfare.mp3"], + ["level_up_fanfare", "bw/level_up_fanfare.mp3"], + ["item_fanfare", "bw/item_fanfare.mp3"], + ["minor_fanfare", "bw/minor_fanfare.mp3"], + ["heal", "bw/heal.mp3"], + ["victory_trainer", "bw/victory_trainer.mp3"], + ["victory_team_plasma", "bw/victory_team_plasma.mp3"], + ["victory_gym", "bw/victory_gym.mp3"], + ["victory_champion", "bw/victory_champion.mp3"], + ["evolution", "bw/evolution.mp3"], + ["evolution_fanfare", "bw/evolution_fanfare.mp3"] +]); + +export const allDefaultSeAssets: Map = new Map([ + ["select", "ui"], + ["menu_open", "ui"], + ["error", "ui"], + ["hit", undefined], + ["hit_strong", undefined], + ["hit_weak", undefined], + ["stat_up", undefined], + ["stat_down", undefined], + ["faint", undefined], + ["flee", undefined], + ["low_hp", undefined], + ["exp", undefined], + ["level_up", undefined], + ["sparkle", undefined], + ["restore", undefined], + ["shine", undefined], + ["shing", undefined], + ["charge", undefined], + ["beam", undefined], + ["upgrade", undefined], + ["buy", undefined], + ["achv", undefined], + + ["pb_rel", undefined], + ["pb_throw", undefined], + ["pb_bounce_1", undefined], + ["pb_bounce_2", undefined], + ["pb_move", undefined], + ["pb_catch", undefined], + ["pb_lock", undefined], + + ["pb_tray_enter", undefined], + ["pb_tray_ball", undefined], + ["pb_tray_empty", undefined], + + ["egg_crack", undefined], + ["egg_hatch", undefined], + ["gacha_dial", undefined], + ["gacha_running", undefined], + ["gacha_dispense", undefined], + + ["PRSFX- Transform", "battle_anims"] +]); + diff --git a/src/loading-scene.ts b/src/loading-scene.ts index c3cb494d497..a7f37fda9ed 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -23,6 +23,7 @@ import { initVouchers } from "./system/voucher"; import { Biome } from "#enums/biome"; import { TrainerType } from "#enums/trainer-type"; import {initMysteryEncounters} from "#app/data/mystery-encounters/mystery-encounters"; +import { allDefaultBgmAssets, allDefaultSeAssets } from "#app/default-assets"; export class LoadingScene extends SceneBase { public static readonly KEY = "loading"; @@ -297,61 +298,13 @@ export class LoadingScene extends SceneBase { this.loadAtlas("xbox", "inputs"); this.loadAtlas("keyboard", "inputs"); - this.loadSe("select", "ui"); - this.loadSe("menu_open", "ui"); - this.loadSe("error", "ui"); - this.loadSe("hit"); - this.loadSe("hit_strong"); - this.loadSe("hit_weak"); - this.loadSe("stat_up"); - this.loadSe("stat_down"); - this.loadSe("faint"); - this.loadSe("flee"); - this.loadSe("low_hp"); - this.loadSe("exp"); - this.loadSe("level_up"); - this.loadSe("sparkle"); - this.loadSe("restore"); - this.loadSe("shine"); - this.loadSe("shing"); - this.loadSe("charge"); - this.loadSe("beam"); - this.loadSe("upgrade"); - this.loadSe("buy"); - this.loadSe("achv"); + for (const key of allDefaultSeAssets.keys()) { + this.loadSe(key, allDefaultSeAssets.get(key)); + } - this.loadSe("pb_rel"); - this.loadSe("pb_throw"); - this.loadSe("pb_bounce_1"); - this.loadSe("pb_bounce_2"); - this.loadSe("pb_move"); - this.loadSe("pb_catch"); - this.loadSe("pb_lock"); - - this.loadSe("pb_tray_enter"); - this.loadSe("pb_tray_ball"); - this.loadSe("pb_tray_empty"); - - this.loadSe("egg_crack"); - this.loadSe("egg_hatch"); - this.loadSe("gacha_dial"); - this.loadSe("gacha_running"); - this.loadSe("gacha_dispense"); - - this.loadSe("PRSFX- Transform", "battle_anims"); - - this.loadBgm("menu"); - - this.loadBgm("level_up_fanfare", "bw/level_up_fanfare.mp3"); - this.loadBgm("item_fanfare", "bw/item_fanfare.mp3"); - this.loadBgm("minor_fanfare", "bw/minor_fanfare.mp3"); - this.loadBgm("heal", "bw/heal.mp3"); - this.loadBgm("victory_trainer", "bw/victory_trainer.mp3"); - this.loadBgm("victory_team_plasma", "bw/victory_team_plasma.mp3"); - this.loadBgm("victory_gym", "bw/victory_gym.mp3"); - this.loadBgm("victory_champion", "bw/victory_champion.mp3"); - this.loadBgm("evolution", "bw/evolution.mp3"); - this.loadBgm("evolution_fanfare", "bw/evolution_fanfare.mp3"); + for (const key of allDefaultBgmAssets.keys()) { + this.loadBgm(key, allDefaultBgmAssets.get(key)); + } this.load.plugin("rextexteditplugin", "https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rextexteditplugin.min.js", true); diff --git a/src/phases/new-biome-encounter-phase.ts b/src/phases/new-biome-encounter-phase.ts index 2a526a22ee2..bfb97454082 100644 --- a/src/phases/new-biome-encounter-phase.ts +++ b/src/phases/new-biome-encounter-phase.ts @@ -8,6 +8,12 @@ export class NewBiomeEncounterPhase extends NextEncounterPhase { super(scene); } + start() { + super.start(); + + this.scene.clearAllAudio(); + } + doEncounter(): void { this.scene.playBgm(undefined, true); diff --git a/src/scene-base.ts b/src/scene-base.ts index 298b8096e54..a2a5b39974b 100644 --- a/src/scene-base.ts +++ b/src/scene-base.ts @@ -1,3 +1,5 @@ +import { allDefaultBgmAssets, allDefaultSeAssets } from "#app/default-assets"; + export const legacyCompatibleImages: string[] = []; export class SceneBase extends Phaser.Scene { @@ -91,4 +93,29 @@ export class SceneBase extends Phaser.Scene { } this.load.audio(key, this.getCachedUrl(`audio/bgm/${filename}`)); } + + clearAllAudio() { + let removedAssets = ""; + for (const key of this.cache.audio.entries.keys()) { + const audioKey = key as string; + const keyWithoutFolder = audioKey.split("/").pop(); + if (allDefaultBgmAssets.has(audioKey) || (keyWithoutFolder && allDefaultSeAssets.has(keyWithoutFolder))) { + // Default audio asset, don't unload + continue; + } + + // TODO: filter for player's Pokemon assets and do not unload + // if (audioKey.includes("PRSFX - ")) { + // // Asset in use by one of the player's party Pokemon, don't unload + // continue; + // } + + if (this.cache.audio.has(audioKey)) { + removedAssets += `${audioKey}\n`; + this.cache.audio.remove(audioKey); + } + } + + console.log(`Audio keys removed from cache:\n${removedAssets}`); + } }