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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-26 07:13:21 +01:00
parent 5bcc87983e
commit 130f1dc6a5
2 changed files with 31 additions and 8 deletions
+1 -8
View File
@@ -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 {
+30
View File
@@ -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<Self, String> {
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"));