From d9bf3e5c90f16f0db0b616bb129d237311f91982 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Thu, 23 Mar 2023 16:05:02 -0600 Subject: [PATCH] success --- src/config.rs | 28 ++++++++++++++++++++++++++++ src/gui.rs | 28 ++++++++++++++++------------ src/main.rs | 2 +- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/config.rs b/src/config.rs index ee57160..eee37be 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,12 +26,27 @@ pub struct Engine { pub kafka: Option, pub device: Option, pub udp: Option, + pub gui: Option, } #[derive(Serialize, Deserialize, Debug)] pub struct Device { } +#[derive(Serialize, Deserialize, Debug)] +pub struct GUI { + pub up: String, + pub down: String, + pub left: String, + pub right: String, + pub a: String, + pub b: String, + pub x: String, + pub y: String, + pub l: String, + pub r: String, +} + #[derive(Serialize, Deserialize, Debug)] pub struct Kafka { pub addr: String, @@ -75,6 +90,18 @@ fn build_config_std() -> Config { engine: Engine{ 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("up")), + down: env::var("INPUT_GUI_BUTTON_DOWN").unwrap_or(String::from("down")), + left: env::var("INPUT_GUI_BUTTON_LEFT").unwrap_or(String::from("left")), + right: env::var("INPUT_GUI_BUTTON_RIGHT").unwrap_or(String::from("right")), + a: env::var("INPUT_GUI_BUTTON_A").unwrap_or(String::from("a")), + b: env::var("INPUT_GUI_BUTTON_B").unwrap_or(String::from("b")), + x: env::var("INPUT_GUI_BUTTON_X").unwrap_or(String::from("x")), + y: env::var("INPUT_GUI_BUTTON_Y").unwrap_or(String::from("y")), + l: env::var("INPUT_GUI_BUTTON_L").unwrap_or(String::from("l")), + r: env::var("INPUT_GUI_BUTTON_R").unwrap_or(String::from("r")), + }), device: None, udp: Some(UDP{ host: Some(env::var("INPUT_UDP_HOST").unwrap_or(String::from("localhost"))), @@ -90,6 +117,7 @@ fn build_config_std() -> Config { engine: Engine{ name: env::var("OUTPUT_NAME").unwrap_or(String::from("stdout")), kafka: None, + gui: None, device: None, udp: Some(UDP{ host: Some(env::var("OUTPUT_UDP_HOST").unwrap_or(String::from("localhost"))), diff --git a/src/gui.rs b/src/gui.rs index d95e414..1bd75e2 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -6,12 +6,14 @@ use iced::subscription; use iced::{Alignment, Element, Application, Settings, Subscription, Theme, Command}; use crate::stream::OutputStream; +use crate::config::GUI; -pub fn main(output_stream: Box) -> iced::Result { +pub fn main(cfg: GUI, output_stream: Box) -> iced::Result { let def: iced::Settings<()> = Settings::default(); let settings = Settings{ flags: Flags { output_stream: output_stream, + cfg: cfg, }, antialiasing: def.antialiasing, default_font: def.default_font, @@ -34,6 +36,7 @@ struct Main { struct Flags { output_stream: Box, + cfg: GUI, } struct Inputs { @@ -139,18 +142,19 @@ impl Application for Main { modifiers: _, .. }) => { + let nope = String::from(""); let s = match key_code { - _ if key_code == self.inputs.stick.up => String::from("up"), - _ if key_code == self.inputs.stick.down => String::from("down"), - _ if key_code == self.inputs.stick.left => String::from("left"), - _ if key_code == self.inputs.stick.right => String::from("right"), - _ if key_code == self.inputs.a => String::from("a"), - _ if key_code == self.inputs.b => String::from("b"), - _ if key_code == self.inputs.x => String::from("x"), - _ if key_code == self.inputs.y => String::from("y"), - _ if key_code == self.inputs.l => String::from("l"), - _ if key_code == self.inputs.r => String::from("r"), - _ => String::from(""), + _ if key_code == self.inputs.stick.up => &self.flags.cfg.up, + _ if key_code == self.inputs.stick.down => &self.flags.cfg.down, + _ if key_code == self.inputs.stick.left => &self.flags.cfg.left, + _ if key_code == self.inputs.stick.right => &self.flags.cfg.right, + _ if key_code == self.inputs.a => &self.flags.cfg.a, + _ if key_code == self.inputs.b => &self.flags.cfg.b, + _ if key_code == self.inputs.x => &self.flags.cfg.x, + _ if key_code == self.inputs.y => &self.flags.cfg.y, + _ if key_code == self.inputs.l => &self.flags.cfg.l, + _ if key_code == self.inputs.r => &self.flags.cfg.r, + _ => &nope, }; if s.len() > 0 { self.flags.output_stream.put(s.chars().collect()); diff --git a/src/main.rs b/src/main.rs index 5eba371..b1a043a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ fn main() { let cfg = config::build_config().unwrap(); if cfg.streams.input.engine.name == "gui" { let output_stream = stream::build_output_stream(&cfg.streams.output); - gui::main(output_stream).unwrap(); + gui::main(cfg.streams.input.engine.gui.unwrap(), output_stream).unwrap(); } else { main_cli(cfg); }