From 130f1dc6a5a83917bd89477414b528e640cefc6f Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 26 Oct 2026 07:13:21 +0100 Subject: [PATCH] horizon-ctl options-set keeps the mod list options-set rebuilt Settings from options.txt and carried over Horizon's graphics, controller and extras files, but not the mod list: every mod read as off afterwards, and the next save wrote an empty horizon-mods.txt. Settings::with_option now does the rebuild and keeps all four. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/options.rs | 9 +------ crates/horizon-client/src/settings.rs | 30 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index 0e385e25c..3a61b0e7a 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -57,14 +57,7 @@ impl Game<'_> { .map(str::trim) .filter(|v| !v.is_empty()) .ok_or("options-set KEY VALUE: missing the value")?; - let mut file = self.settings.to_file(); - file.set_text(key, value)?; - let mut settings = horizon_client::settings::Settings::from_file(file); - // Horizon's own files are not in options.txt. - std::mem::swap(&mut settings.horizon, &mut self.settings.horizon); - std::mem::swap(&mut settings.controller, &mut self.settings.controller); - std::mem::swap(&mut settings.extras, &mut self.settings.extras); - self.settings = settings; + self.settings = self.settings.with_option(key, value)?; // As the options screen applies a change. self.handle_option_events(vec![Event::Changed])?; match *key { diff --git a/crates/horizon-client/src/settings.rs b/crates/horizon-client/src/settings.rs index 2a53e1702..ebffc897f 100644 --- a/crates/horizon-client/src/settings.rs +++ b/crates/horizon-client/src/settings.rs @@ -538,6 +538,21 @@ impl Settings { } f } + /// These settings with one `options.txt` value changed (`horizon-ctl + /// options-set`, as `OptionsFile::set_text` reads it). Horizon's own + /// files (graphics, controller, extras, the mod list) aren't in + /// `options.txt`, so they stay as they are. + pub fn with_option(&self, key: &str, value: &str) -> Result { + let mut file = self.to_file(); + file.set_text(key, value)?; + Ok(Self { + horizon: self.horizon.clone(), + controller: self.controller.clone(), + extras: self.extras.clone(), + mods: self.mods.clone(), + ..Self::from_file(file) + }) + } /// The `options.txt` text (Options.save). pub fn serialize(&self) -> String { self.to_file().serialize() @@ -592,6 +607,21 @@ impl Settings { mod tests { use super::*; #[test] + fn an_option_set_keeps_horizon_files() { + let mut s = Settings::parse("fov:70\n"); + s.mods.enabled.insert("zoom".into()); + s.extras.minimap = true; + s.horizon.fog = !s.horizon.fog; + s.controller.vibration = !s.controller.vibration; + let set = s.with_option("fov", "90").unwrap(); + assert_eq!(set.fov, 90.0); + assert_eq!(set.mods, s.mods); + assert_eq!(set.extras, s.extras); + assert_eq!(set.horizon, s.horizon); + assert_eq!(set.controller, s.controller); + assert!(s.with_option("fov", "200").is_err()); + } + #[test] fn gui_scale_survives_temporary_small_framebuffer() { for requested in [0, 1, 2, 6] { let settings = Settings::parse(&format!("guiScale:{requested}\n"));