From 153fe170ddfddd4ddd1a61b6ab89148547c29120 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Fri, 10 Jan 2025 22:46:50 +0100 Subject: [PATCH] Add new bind keys (should be all). Give mouse bind keys a prefix. --- game/binds/src/binds.rs | 10 ++-- .../src/console/local_console.rs | 49 +++++++++++++++++-- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/game/binds/src/binds.rs b/game/binds/src/binds.rs index 891f99b..166afa4 100644 --- a/game/binds/src/binds.rs +++ b/game/binds/src/binds.rs @@ -278,7 +278,9 @@ fn bind_keys_str_to_bind_keys(bind_keys_str: &str) -> anyhow::Result(&bind_key_str) { bind_keys.push(BindKey::Key(PhysicalKey::Code(key_code))); - } else if let Ok(key_code) = serde_json::from_str::<_>(&bind_key_str) { + } else if let Ok(key_code) = + serde_json::from_str::<_>(&bind_key_str.replacen("\"Mouse", "\"", 1)) + { bind_keys.push(BindKey::Mouse(key_code)); } else if let Ok(key_code) = serde_json::from_str::<_>(&bind_key_str) { bind_keys.push(BindKey::Extra(key_code)); @@ -374,13 +376,13 @@ pub fn bind_keys_to_str(bind_keys: &[BindKey]) -> String { } }, BindKey::Mouse(btn) => { - res.push_str( + res.push_str(&format!( + "mouse_{}", replace_inner_upper_with_underscore( &serde_json::to_string(btn).unwrap().replace('"', ""), ) .to_lowercase() - .as_str(), - ); + )); } BindKey::Extra(ext) => { res.push_str( diff --git a/game/client-console/src/console/local_console.rs b/game/client-console/src/console/local_console.rs index 4759ab1..331dc51 100644 --- a/game/client-console/src/console/local_console.rs +++ b/game/client-console/src/console/local_console.rs @@ -333,6 +333,8 @@ impl LocalConsoleBuilder { ty: CommandArgType::TextArrayFrom { from: { let mut res = vec![]; + + // keyboard for i in 'a'..='z' { res.push(i.to_string()); } @@ -350,6 +352,8 @@ impl LocalConsoleBuilder { res.push("numpad_add".to_string()); res.push("numpad_multiply".to_string()); res.push("numpad_divide".to_string()); + res.push("numpad_comma".to_string()); + res.push("numpad_enter".to_string()); for i in 0..=9 { res.push(format!("digit{}", i)); @@ -363,9 +367,16 @@ impl LocalConsoleBuilder { res.push("pause".to_string()); - res.push("left".to_string()); - res.push("right".to_string()); - res.push("middle".to_string()); + res.push("equal".to_string()); + res.push("minus".to_string()); + res.push("period".to_string()); + res.push("quote".to_string()); + res.push("semicolon".to_string()); + res.push("slash".to_string()); + + res.push("backspace".to_string()); + + res.push("caps_lock".to_string()); res.push("arrow_left".to_string()); res.push("arrow_right".to_string()); @@ -381,12 +392,42 @@ impl LocalConsoleBuilder { res.push("alt_left".to_string()); res.push("alt_right".to_string()); + res.push("print_screen".to_string()); + + // TODO: are these useful? + // res.push("context_menu".to_string()); + // res.push("super_left".to_string()); + // res.push("super_right".to_string()); + // res.push("num_lock".to_string()); + res.push("space".to_string()); res.push("tab".to_string()); + res.push("delete".to_string()); + res.push("end".to_string()); + + res.push("home".to_string()); + res.push("insert".to_string()); + + res.push("backquote".to_string()); + res.push("backslash".to_string()); + + res.push("bracket_left".to_string()); + res.push("bracket_right".to_string()); + + res.push("comma".to_string()); + + // mouse + res.push("mouse_left".to_string()); + res.push("mouse_right".to_string()); + res.push("mouse_middle".to_string()); + res.push("mouse_back".to_string()); + res.push("mouse_forward".to_string()); + + // mouse wheel res.push("wheel_down".to_string()); res.push("wheel_up".to_string()); - // TODO: add lot more + res.into_iter().map(|s| s.try_into().unwrap()).collect() }, separator: '+',