mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-01-15 23:36:41 +00:00
BGM lookup paths instead of one hardcoded
This commit is contained in:
parent
3f7174df66
commit
ab7902dac1
|
@ -117,6 +117,7 @@ pub struct EngineConstants {
|
|||
pub font_path: String,
|
||||
pub font_scale: f32,
|
||||
pub font_space_offset: f32,
|
||||
pub organya_paths: Vec<String>,
|
||||
}
|
||||
|
||||
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
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue