mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add auto generation of settings.toml if it does not already exist
Former-commit-id: 941b81a8faeff89096256666c56ae472d9b569d5
This commit is contained in:
parent
9592eb67c5
commit
515039c62d
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@
|
||||
# Veloren
|
||||
**/server_conf.toml
|
||||
**/keybinds.toml
|
||||
**/settings.toml
|
||||
assets/voxygen
|
||||
*.rar
|
||||
|
||||
|
@ -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"
|
@ -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");
|
||||
|
||||
|
@ -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<Self, ConfigError> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user