diff --git a/ferretro_components/examples/multifunction_emulator.rs b/ferretro_components/examples/multifunction_emulator.rs index 5f4cd38..f6282e1 100644 --- a/ferretro_components/examples/multifunction_emulator.rs +++ b/ferretro_components/examples/multifunction_emulator.rs @@ -119,13 +119,15 @@ pub fn main() -> Result<(), Box> { emu.register_component(StderrSysInfoLogComponent::default())?; } - let mut variables = VariableStoreComponent::default(); + emu.register_component(EnvironmentVariableComponent::default())?; + + let mut var_store = VariableStoreComponent::default(); // TODO: load a config file specified on the CLI - variables.insert("mgba_skip_bios", "ON"); - variables.insert("gpsp_drc", "enabled"); - variables.insert("gpsp_frame_mixing", "enabled"); - variables.insert("gpsp_save_method", "libretro"); - emu.register_component(variables)?; + var_store.insert("mgba_skip_bios", "ON"); + var_store.insert("gpsp_drc", "enabled"); + var_store.insert("gpsp_frame_mixing", "enabled"); + var_store.insert("gpsp_save_method", "libretro"); + emu.register_component(var_store)?; emu.init()?; emu.load_game(&opt.rom)?; diff --git a/ferretro_components/src/provided/stdlib/mod.rs b/ferretro_components/src/provided/stdlib/mod.rs index bc502b0..0e5cdc9 100644 --- a/ferretro_components/src/provided/stdlib/mod.rs +++ b/ferretro_components/src/provided/stdlib/mod.rs @@ -16,4 +16,4 @@ pub use input::StatefulInputComponent; pub use paths::PathBufComponent; pub use print::*; pub use saves::LocalFileSaveComponent; -pub use variables::VariableStoreComponent; +pub use variables::*; diff --git a/ferretro_components/src/provided/stdlib/variables/env.rs b/ferretro_components/src/provided/stdlib/variables/env.rs index c73b3bf..cf3d509 100644 --- a/ferretro_components/src/provided/stdlib/variables/env.rs +++ b/ferretro_components/src/provided/stdlib/variables/env.rs @@ -15,19 +15,22 @@ impl RetroCallbacks for EnvironmentVariableComponent { fn set_variables(&mut self, variables: &[Variable2]) -> Option { for v in variables { - println!("# {}", v.description); - let value = if let Ok(x) = std::env::var(&v.key) { - if !v.options.contains(&x) { - panic!("Invalid value {:?} for variable {:?} (expected one of {:?})", x, v.key, v.options); - } else if x != v.options[0] { + println!( + "# {}: {}", + v.description, + v.options.iter().map(String::as_str).collect::>().join(", ") + ); + if let Ok(value) = std::env::var(&v.key) { + if !v.options.contains(&value) { + panic!("Invalid value {:?} for variable {:?} (expected one of {:?})", value, v.key, v.options); + } else if value != v.options[0] { println!("# (overridden, default {})", v.options[0]); } - x + println!("{}={}", v.key, value); + self.variables.insert(v.key.to_owned(), value); } else { - v.options[0].clone() - }; - println!("{}={} # {:?}", v.key, value, v.options); - self.variables.insert(v.key.to_owned(), value); + println!("{}=", v.key); + } } Some(true) }