From 780e034674b20728a7680baba1429cfb8009c6ac Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Tue, 16 Apr 2019 11:41:39 -0600 Subject: [PATCH] Add better defaults support Former-commit-id: fa77acae3ee2b99cbf37a8fec71ee1913e889d82 --- voxygen/src/settings.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index d72e5c5da4..52f772af2e 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -7,9 +7,11 @@ use glutin::VirtualKeyCode; use toml; use std::fs::File; use std::io::prelude::*; +use std::default::Default; /// Settings contains everything that can be configured in the Settings.toml file #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(default)] pub struct Settings { pub controls: ControlSettings, } @@ -35,8 +37,8 @@ pub struct ControlSettings { pub interface: VirtualKeyCode, } -impl Settings { - pub fn default() -> Self { +impl Default for Settings { + fn default() -> Self { Settings { controls: ControlSettings { toggle_cursor: VirtualKeyCode::Tab, @@ -53,14 +55,18 @@ impl Settings { social: VirtualKeyCode::O, spellbook: VirtualKeyCode::P, settings: VirtualKeyCode::N, - help: VirtualKeyCode::F2, + help: VirtualKeyCode::F1, interface: VirtualKeyCode::F2, }, } } +} + +impl Settings { pub fn load() -> Result { let mut config = Config::new(); + config.merge(Config::try_from(&Settings::default())?); config.merge(config::File::with_name("settings"))?; config.try_into() }