aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-03 12:39:41 +0300
committerValentin Popov <valentin@popov.link>2026-12-03 12:39:41 +0300
commit6c85147ebb73ad3c8b933ad3fa1f9025313ed3fe (patch)
tree91bbfc8bdefbc205e029f5d545f41b80be5bb8bf /crates/fparkan-assets/src
parente59c55289c494a5bd0126b6c40bc4e07a52b8a28 (diff)
downloadfparkan-6c85147ebb73ad3c8b933ad3fa1f9025313ed3fe.tar.xz
fparkan-6c85147ebb73ad3c8b933ad3fa1f9025313ed3fe.zip
feat(audio): apply the installed effects and music levels
Diffstat (limited to 'crates/fparkan-assets/src')
-rw-r--r--crates/fparkan-assets/src/game_settings.rs37
1 files changed, 37 insertions, 0 deletions
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<f32>,
+ pub cd_gain: Option<f32>,
+ 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);
+}