From a0adc492382510eec4da0d61d7025af393c92966 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Feb 2020 11:47:57 +0900 Subject: [PATCH] attempt to fix issue #1 --- .gitignore | 3 ++- src/sound/sound_channel.rs | 2 +- src/sound/sound_manager.rs | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 54e5df7..ce90f58 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ **/*.rs.bk /soundpack /soundpack_modified -/ignore.txt \ No newline at end of file +/ignore.txt +soundpack.zip \ No newline at end of file diff --git a/src/sound/sound_channel.rs b/src/sound/sound_channel.rs index efefa62..e903581 100644 --- a/src/sound/sound_channel.rs +++ b/src/sound/sound_channel.rs @@ -20,7 +20,7 @@ impl SoundChannel { } pub fn maintain(&mut self, device: &Device, rng: &mut ThreadRng, _ui_handle: Option<&UIHandle>) { - let delay = self.delay.checked_sub(100).unwrap_or(0); + let delay = self.delay.saturating_sub(100); self.delay = delay; self.one_shots.retain(|s| { if delay != 0 { diff --git a/src/sound/sound_manager.rs b/src/sound/sound_manager.rs index 176c560..f69b912 100644 --- a/src/sound/sound_manager.rs +++ b/src/sound/sound_manager.rs @@ -15,7 +15,7 @@ pub struct SoundManager { impl SoundManager { pub fn new(sound_dir: &Path, mut ui_handle: UIHandle) -> Self { let mut sounds = Vec::new(); - let device = default_output_device().unwrap(); + let device = default_output_device().expect("Failed to get default audio output device."); let mut channels : HashMap, SoundChannel> = HashMap::new(); channels.insert( String::from("misc").into_boxed_str(), @@ -28,7 +28,7 @@ impl SoundManager { let path = entry.path(); if path.is_dir() { visit_dir(&path, func); - } else if path.is_file() && path.extension().unwrap() == "xml" { + } else if path.is_file() && path.extension().map_or(false, |ext| ext=="xml") { func(&path); } } @@ -241,8 +241,8 @@ impl SoundManager { let sounds = &mut self.sounds; let recent = &mut self.recent; recent.retain(|&i| { - let timeout = sounds[i].current_timeout.checked_sub(100).unwrap_or(0); - let recent_call = sounds[i].recent_call.checked_sub(1).unwrap_or(0); + let timeout = sounds[i].current_timeout.saturating_sub(100); + let recent_call = sounds[i].recent_call.saturating_sub(1); sounds[i].current_timeout = timeout; sounds[i].recent_call = recent_call; timeout != 0