From ab7902dac1b58d6af286c4063c3ee9ff390ad22a Mon Sep 17 00:00:00 2001 From: Alula Date: Sat, 5 Sep 2020 05:31:55 +0200 Subject: [PATCH] BGM lookup paths instead of one hardcoded --- src/engine_constants.rs | 7 +++++++ src/sound/mod.rs | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/engine_constants.rs b/src/engine_constants.rs index 8b00cf7..cdf3a4b 100644 --- a/src/engine_constants.rs +++ b/src/engine_constants.rs @@ -117,6 +117,7 @@ pub struct EngineConstants { pub font_path: String, pub font_scale: f32, pub font_space_offset: f32, + pub organya_paths: Vec, } impl Clone for EngineConstants { @@ -133,6 +134,7 @@ impl Clone for EngineConstants { font_path: self.font_path.clone(), font_scale: self.font_scale, font_space_offset: self.font_space_offset, + organya_paths: self.organya_paths.clone(), } } } @@ -468,6 +470,11 @@ impl EngineConstants { font_path: str!("builtin/builtin_font.fnt"), font_scale: 1.0, font_space_offset: -3.0, + organya_paths: vec![ + str!("/org/"), // NXEngine + str!("/base/Org/"), // CS+ + str!("/Resource/ORG/"), // CSE2E + ], } } diff --git a/src/sound/mod.rs b/src/sound/mod.rs index 7f14071..86f00f3 100644 --- a/src/sound/mod.rs +++ b/src/sound/mod.rs @@ -6,7 +6,7 @@ use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use crate::engine_constants::EngineConstants; use crate::ggez::{Context, filesystem, GameResult}; -use crate::ggez::GameError::{AudioError, InvalidValue}; +use crate::ggez::GameError::{AudioError, InvalidValue, ResourceLoadError}; use crate::sound::organya::Song; use crate::sound::playback::{PlaybackEngine, SavedPlaybackState}; use crate::sound::wave_bank::SoundBank; @@ -112,7 +112,13 @@ impl SoundManager { self.tx.send(PlaybackMessage::SaveState)?; self.tx.send(PlaybackMessage::Stop)?; } else if let Some(song_name) = SONGS.get(song_id) { - let org = organya::Song::load_from(filesystem::open(ctx, ["/base/Org/", &song_name.to_lowercase(), ".org"].join(""))?)?; + let path = constants.organya_paths + .iter() + .map(|prefix| [prefix, &song_name.to_lowercase(), ".org"].join("")) + .find(|path| filesystem::exists(ctx, path)) + .ok_or_else(|| ResourceLoadError(format!("BGM {:?} does not exist.", song_name)))?; + + let org = organya::Song::load_from(filesystem::open(ctx, path)?)?; log::info!("Playing BGM: {}", song_name); self.prev_song_id = self.current_song_id;