feat: add audio muting button, mute by default in debug builds

This commit is contained in:
2025-07-23 21:00:52 -05:00
parent 076275158e
commit eaa4ab37f9
3 changed files with 37 additions and 13 deletions

View File

@@ -15,6 +15,7 @@ pub struct Audio {
_mixer_context: mixer::Sdl2MixerContext,
sounds: Vec<Chunk>,
next_sound_index: usize,
muted: bool,
}
impl Audio {
@@ -51,6 +52,7 @@ impl Audio {
_mixer_context: mixer_context,
sounds,
next_sound_index: 0,
muted: false,
}
}
@@ -68,4 +70,18 @@ impl Audio {
}
self.next_sound_index = (self.next_sound_index + 1) % self.sounds.len();
}
/// Instantly mute or unmute all channels.
pub fn set_mute(&mut self, mute: bool) {
let channels = 4;
let volume = if mute { 0 } else { 32 };
for i in 0..channels {
mixer::Channel(i).set_volume(volume);
}
self.muted = mute;
}
pub fn is_muted(&self) -> bool {
self.muted
}
}