nest config gui.buttons....

master
Bel LaPointe 2023-03-24 11:20:40 -06:00
parent 400762e5fc
commit 4e41fefe2a
2 changed files with 27 additions and 20 deletions

View File

@ -36,6 +36,11 @@ pub struct Device {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct GUI { pub struct GUI {
pub buttons: Buttons,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Buttons {
pub up: String, pub up: String,
pub down: String, pub down: String,
pub left: String, pub left: String,
@ -93,16 +98,18 @@ fn build_config_std() -> Config {
name: env::var("INPUT_NAME").unwrap_or(String::from("stdin")), name: env::var("INPUT_NAME").unwrap_or(String::from("stdin")),
kafka: None, kafka: None,
gui: Some(GUI{ gui: Some(GUI{
up: env::var("INPUT_GUI_BUTTON_UP").unwrap_or(String::from("w")), buttons: Buttons{
left: env::var("INPUT_GUI_BUTTON_LEFT").unwrap_or(String::from("a")), up: env::var("INPUT_GUI_BUTTON_UP").unwrap_or(String::from("w")),
down: env::var("INPUT_GUI_BUTTON_DOWN").unwrap_or(String::from("s")), left: env::var("INPUT_GUI_BUTTON_LEFT").unwrap_or(String::from("a")),
right: env::var("INPUT_GUI_BUTTON_RIGHT").unwrap_or(String::from("d")), down: env::var("INPUT_GUI_BUTTON_DOWN").unwrap_or(String::from("s")),
a: env::var("INPUT_GUI_BUTTON_A").unwrap_or(String::from("1")), right: env::var("INPUT_GUI_BUTTON_RIGHT").unwrap_or(String::from("d")),
b: env::var("INPUT_GUI_BUTTON_B").unwrap_or(String::from("2")), a: env::var("INPUT_GUI_BUTTON_A").unwrap_or(String::from("1")),
x: env::var("INPUT_GUI_BUTTON_X").unwrap_or(String::from("3")), b: env::var("INPUT_GUI_BUTTON_B").unwrap_or(String::from("2")),
y: env::var("INPUT_GUI_BUTTON_Y").unwrap_or(String::from("4")), x: env::var("INPUT_GUI_BUTTON_X").unwrap_or(String::from("3")),
l: env::var("INPUT_GUI_BUTTON_L").unwrap_or(String::from("q")), y: env::var("INPUT_GUI_BUTTON_Y").unwrap_or(String::from("4")),
r: env::var("INPUT_GUI_BUTTON_R").unwrap_or(String::from("e")), 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, device: None,
udp: Some(UDP{ udp: Some(UDP{

View File

@ -82,16 +82,16 @@ fn controller_button_to_string(btn: Message, cur: iced::keyboard::KeyCode) -> St
impl Main { impl Main {
fn key_code_to_string(&self, key_code: &iced::keyboard::KeyCode) -> Option<&String> { fn key_code_to_string(&self, key_code: &iced::keyboard::KeyCode) -> Option<&String> {
match key_code { match key_code {
_ if key_code == &self.inputs.stick.up => Some(&self.flags.cfg.up), _ if key_code == &self.inputs.stick.up => Some(&self.flags.cfg.buttons.up),
_ if key_code == &self.inputs.stick.down => Some(&self.flags.cfg.down), _ if key_code == &self.inputs.stick.down => Some(&self.flags.cfg.buttons.down),
_ if key_code == &self.inputs.stick.left => Some(&self.flags.cfg.left), _ if key_code == &self.inputs.stick.left => Some(&self.flags.cfg.buttons.left),
_ if key_code == &self.inputs.stick.right => Some(&self.flags.cfg.right), _ if key_code == &self.inputs.stick.right => Some(&self.flags.cfg.buttons.right),
_ if key_code == &self.inputs.a => Some(&self.flags.cfg.a), _ if key_code == &self.inputs.a => Some(&self.flags.cfg.buttons.a),
_ if key_code == &self.inputs.b => Some(&self.flags.cfg.b), _ if key_code == &self.inputs.b => Some(&self.flags.cfg.buttons.b),
_ if key_code == &self.inputs.x => Some(&self.flags.cfg.x), _ if key_code == &self.inputs.x => Some(&self.flags.cfg.buttons.x),
_ if key_code == &self.inputs.y => Some(&self.flags.cfg.y), _ if key_code == &self.inputs.y => Some(&self.flags.cfg.buttons.y),
_ if key_code == &self.inputs.l => Some(&self.flags.cfg.l), _ if key_code == &self.inputs.l => Some(&self.flags.cfg.buttons.l),
_ if key_code == &self.inputs.r => Some(&self.flags.cfg.r), _ if key_code == &self.inputs.r => Some(&self.flags.cfg.buttons.r),
_ => None, _ => None,
} }
} }