aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/audio.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-01-04 21:45:32 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-01-04 21:45:32 +0100
commit38a9a4d11821fe5b9948d4a94935e5ccb103fdf2 (patch)
treebfa84dc3a6b914dbeba0f43a0ee9f0138d17b987 /mumd/src/audio.rs
parentea65db55764bf369d8e02ca8bae9088c738b020b (diff)
downloadmum-38a9a4d11821fe5b9948d4a94935e5ccb103fdf2.tar.gz
cows aren't optional
Diffstat (limited to 'mumd/src/audio.rs')
-rw-r--r--mumd/src/audio.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs
index b5b5c7f..569cdc5 100644
--- a/mumd/src/audio.rs
+++ b/mumd/src/audio.rs
@@ -248,10 +248,11 @@ impl Audio {
self.sounds = NotificationEvents::iter()
.map(|event| {
- let bytes = overrides.get(&event)
- .map(|file| get_resource(file))
- .flatten()
- .unwrap_or(Cow::from(include_bytes!("fallback_sfx.wav").as_ref()));
+
+ let bytes = match overrides.get(&event) {
+ Some(file) => get_sfx(file),
+ None => get_default_sfx(),
+ };
let reader = hound::WavReader::new(bytes.as_ref()).unwrap();
let spec = reader.spec();
let samples = match spec.sample_format {
@@ -382,14 +383,19 @@ impl Audio {
}
// moo
-fn get_resource(file: &str) -> Option<Cow<'static, [u8]>> {
+fn get_sfx(file: &str) -> Cow<'static, [u8]> {
let mut buf: Vec<u8> = Vec::new();
if let Ok(mut file) = File::open(file)
.or_else(|_| File::open(format!("/home/gustav/dev/mum/mumd/src/resources/{}", file)))
{
file.read_to_end(&mut buf).unwrap();
- Some(Cow::from(buf))
+ Cow::from(buf)
} else {
- None
+ warn!("File not found: '{}'", file);
+ get_default_sfx()
}
}
+
+fn get_default_sfx() -> Cow<'static, [u8]> {
+ Cow::from(include_bytes!("fallback_sfx.wav").as_ref())
+}