From 4e41fefe2aa7b66e10f4b2a7081c5eee68378a84 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 24 Mar 2023 11:20:40 -0600 Subject: [PATCH] nest config gui.buttons.... --- src/config.rs | 27 +++++++++++++++++---------- src/gui.rs | 20 ++++++++++---------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/config.rs b/src/config.rs index 39fe31e..e9827c4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,6 +36,11 @@ pub struct Device { #[derive(Serialize, Deserialize, Debug)] pub struct GUI { + pub buttons: Buttons, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Buttons { pub up: String, pub down: String, pub left: String, @@ -93,16 +98,18 @@ fn build_config_std() -> Config { name: env::var("INPUT_NAME").unwrap_or(String::from("stdin")), kafka: None, gui: Some(GUI{ - up: env::var("INPUT_GUI_BUTTON_UP").unwrap_or(String::from("w")), - left: env::var("INPUT_GUI_BUTTON_LEFT").unwrap_or(String::from("a")), - down: env::var("INPUT_GUI_BUTTON_DOWN").unwrap_or(String::from("s")), - right: env::var("INPUT_GUI_BUTTON_RIGHT").unwrap_or(String::from("d")), - a: env::var("INPUT_GUI_BUTTON_A").unwrap_or(String::from("1")), - b: env::var("INPUT_GUI_BUTTON_B").unwrap_or(String::from("2")), - x: env::var("INPUT_GUI_BUTTON_X").unwrap_or(String::from("3")), - y: env::var("INPUT_GUI_BUTTON_Y").unwrap_or(String::from("4")), - l: env::var("INPUT_GUI_BUTTON_L").unwrap_or(String::from("q")), - r: env::var("INPUT_GUI_BUTTON_R").unwrap_or(String::from("e")), + buttons: Buttons{ + up: env::var("INPUT_GUI_BUTTON_UP").unwrap_or(String::from("w")), + left: env::var("INPUT_GUI_BUTTON_LEFT").unwrap_or(String::from("a")), + down: env::var("INPUT_GUI_BUTTON_DOWN").unwrap_or(String::from("s")), + right: env::var("INPUT_GUI_BUTTON_RIGHT").unwrap_or(String::from("d")), + a: env::var("INPUT_GUI_BUTTON_A").unwrap_or(String::from("1")), + b: env::var("INPUT_GUI_BUTTON_B").unwrap_or(String::from("2")), + x: env::var("INPUT_GUI_BUTTON_X").unwrap_or(String::from("3")), + y: env::var("INPUT_GUI_BUTTON_Y").unwrap_or(String::from("4")), + l: env::var("INPUT_GUI_BUTTON_L").unwrap_or(String::from("q")), + r: env::var("INPUT_GUI_BUTTON_R").unwrap_or(String::from("e")), + }, }), device: None, udp: Some(UDP{ diff --git a/src/gui.rs b/src/gui.rs index 2b6d479..dd466be 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -82,16 +82,16 @@ fn controller_button_to_string(btn: Message, cur: iced::keyboard::KeyCode) -> St impl Main { fn key_code_to_string(&self, key_code: &iced::keyboard::KeyCode) -> Option<&String> { match key_code { - _ if key_code == &self.inputs.stick.up => Some(&self.flags.cfg.up), - _ if key_code == &self.inputs.stick.down => Some(&self.flags.cfg.down), - _ if key_code == &self.inputs.stick.left => Some(&self.flags.cfg.left), - _ if key_code == &self.inputs.stick.right => Some(&self.flags.cfg.right), - _ if key_code == &self.inputs.a => Some(&self.flags.cfg.a), - _ if key_code == &self.inputs.b => Some(&self.flags.cfg.b), - _ if key_code == &self.inputs.x => Some(&self.flags.cfg.x), - _ if key_code == &self.inputs.y => Some(&self.flags.cfg.y), - _ if key_code == &self.inputs.l => Some(&self.flags.cfg.l), - _ if key_code == &self.inputs.r => Some(&self.flags.cfg.r), + _ if key_code == &self.inputs.stick.up => Some(&self.flags.cfg.buttons.up), + _ if key_code == &self.inputs.stick.down => Some(&self.flags.cfg.buttons.down), + _ if key_code == &self.inputs.stick.left => Some(&self.flags.cfg.buttons.left), + _ if key_code == &self.inputs.stick.right => Some(&self.flags.cfg.buttons.right), + _ if key_code == &self.inputs.a => Some(&self.flags.cfg.buttons.a), + _ if key_code == &self.inputs.b => Some(&self.flags.cfg.buttons.b), + _ if key_code == &self.inputs.x => Some(&self.flags.cfg.buttons.x), + _ if key_code == &self.inputs.y => Some(&self.flags.cfg.buttons.y), + _ if key_code == &self.inputs.l => Some(&self.flags.cfg.buttons.l), + _ if key_code == &self.inputs.r => Some(&self.flags.cfg.buttons.r), _ => None, } }