diff --git a/.gitignore b/.gitignore index fbac64f787..96ef2e499f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ # Veloren **/server_conf.toml **/keybinds.toml +**/settings.toml assets/voxygen *.rar diff --git a/voxygen/Settings.toml b/voxygen/Settings.toml deleted file mode 100644 index 238f3fd281..0000000000 --- a/voxygen/Settings.toml +++ /dev/null @@ -1,17 +0,0 @@ -[controls] -toggle_cursor = "tab" -escape = "escape" -enter = "return" -move_forward = "w" -move_left = "a" -move_back = "s" -move_right = "d" -map = "m" -bag = "b" -quest_log = "l" -character_window = "c" -social = "o" -spellbook = "p" -settings = "n" -help = "f1" -interface = "f2" diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 41e5bd041a..b31bef5e61 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -77,7 +77,11 @@ fn main() { // Set up the global state let settings = match Settings::load() { Ok(settings) => settings, - Err(err) => Settings::default(), + Err(err) => { + let settings = Settings::default(); + settings.save_to_file(); + settings + }, }; let window = Window::new(&settings).expect("Failed to create window"); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 3678b879f4..d72e5c5da4 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -3,8 +3,10 @@ use config::{ ConfigError, }; use serde_derive::{Serialize, Deserialize}; - use glutin::VirtualKeyCode; +use toml; +use std::fs::File; +use std::io::prelude::*; /// Settings contains everything that can be configured in the Settings.toml file #[derive(Clone, Debug, Serialize, Deserialize)] @@ -56,9 +58,17 @@ impl Settings { }, } } + pub fn load() -> Result { let mut config = Config::new(); - config.merge(config::File::with_name("Settings"))?; + config.merge(config::File::with_name("settings"))?; config.try_into() } + + pub fn save_to_file(&self) -> std::io::Result<()> { + let mut config_file = File::create("settings.toml")?; + let s: &str = &toml::to_string_pretty(self).unwrap(); + config_file.write_all(s.as_bytes()).unwrap(); + Ok(()) + } }