Skip to content

Commit

Permalink
Merge pull request #56 from Jupeyy/pr_better_bind_keys
Browse files Browse the repository at this point in the history
Add new bind keys (should be all).
  • Loading branch information
Jupeyy authored Jan 10, 2025
2 parents 4e8ce51 + 153fe17 commit 1961fde
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
10 changes: 6 additions & 4 deletions game/binds/src/binds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ fn bind_keys_str_to_bind_keys(bind_keys_str: &str) -> anyhow::Result<Vec<BindKey
let bind_key_str = format!("\"{cap_bind_key_str}\"");
if let Ok(key_code) = serde_json::from_str::<KeyCode>(&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));
Expand Down Expand Up @@ -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(
Expand Down
49 changes: 45 additions & 4 deletions game/client-console/src/console/local_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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));
Expand All @@ -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());
Expand All @@ -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: '+',
Expand Down

0 comments on commit 1961fde

Please sign in to comment.