From 6c85147ebb73ad3c8b933ad3fa1f9025313ed3fe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 3 Dec 2026 13:39:41 +0400 Subject: feat(audio): apply the installed effects and music levels --- crates/fparkan-assets/src/game_settings.rs | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'crates/fparkan-assets') diff --git a/crates/fparkan-assets/src/game_settings.rs b/crates/fparkan-assets/src/game_settings.rs index a57d3f62..fe424d0d 100644 --- a/crates/fparkan-assets/src/game_settings.rs +++ b/crates/fparkan-assets/src/game_settings.rs @@ -49,6 +49,19 @@ impl GameSettings { windowed: self.integer("WINDOW_MODE").unwrap_or(1) != 0, }) } + + /// Reads separate wave and CD volume settings from the original profile. + pub fn audio(&self) -> AudioSettings { + let gain = |key| { + self.integer(key) + .map(|value| value.clamp(0, 100) as f32 * 0.01) + }; + AudioSettings { + effects_gain: gain("SFX_VOLUME"), + cd_gain: gain("CD_VOLUME"), + play_cd: self.integer("PLAY_CD_MUSIC").unwrap_or_default() != 0, + } + } } /// The size, color depth and display mode requested by the legacy profile. @@ -68,6 +81,14 @@ impl DisplaySettings { } } +/// Initial gains by sound source. Omitted controls leave the mixer defaults. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct AudioSettings { + pub effects_gain: Option, + pub cd_gain: Option, + pub play_cd: bool, +} + #[cfg(test)] #[test] fn reads_the_original_display_profile_and_scores_video_modes() { @@ -81,3 +102,19 @@ fn reads_the_original_display_profile_and_scores_video_modes() { assert_eq!(display.mode_distance([799, 601], 16), 200); assert!(GameSettings::default().display().is_none()); } + +#[cfg(test)] +#[test] +fn reads_separate_effects_and_cd_controls() { + let settings = GameSettings(Arc::from( + &b"[CS]\nSFX_VOLUME=20\nCD_VOLUME=120\nPLAY_CD_MUSIC=0\n[OTHER]\nSFX_VOLUME=60"[..], + )); + let audio = settings.audio(); + assert!((audio.effects_gain.unwrap() - 0.2).abs() < f32::EPSILON); + assert_eq!(audio.cd_gain, Some(1.0)); + assert!(!audio.play_cd); + assert_eq!(GameSettings::default().audio().effects_gain, None); + let music = GameSettings(Arc::from(&b"[CS]\nCD_VOLUME=0\nPLAY_CD_MUSIC=1"[..])); + assert_eq!(music.audio().cd_gain, Some(0.0)); + assert!(music.audio().play_cd); +} -- cgit v1.2.3