diff options
| author | Radio <radiohotline@disroot.org> | 2026-06-04 15:15:11 +0300 |
|---|---|---|
| committer | Radio <radiohotline@disroot.org> | 2026-06-04 15:15:11 +0300 |
| commit | 9d74b49ab62908d4acf53dde444413886b8b28e5 (patch) | |
| tree | 0cb785267ea7e239b19d88684c0d64b9bd5d52f0 /addons/escoria-ui-keyboard-9verbs/input_map.gd | |
| parent | 2c85d452ad02a5f89cd43bad7f9de31d0e4fa0c1 (diff) | |
escoria setup and old branch archives
Diffstat (limited to 'addons/escoria-ui-keyboard-9verbs/input_map.gd')
| -rw-r--r-- | addons/escoria-ui-keyboard-9verbs/input_map.gd | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/addons/escoria-ui-keyboard-9verbs/input_map.gd b/addons/escoria-ui-keyboard-9verbs/input_map.gd new file mode 100644 index 0000000..8e819c8 --- /dev/null +++ b/addons/escoria-ui-keyboard-9verbs/input_map.gd @@ -0,0 +1,60 @@ +const ACTION_SET_VERB_OPEN = "set_action_verb_open" +const ACTION_SET_VERB_PICKUP = "set_action_verb_pickup" +const ACTION_SET_VERB_PUSH = "set_action_verb_push" +const ACTION_SET_VERB_CLOSE = "set_action_verb_close" +const ACTION_SET_VERB_LOOK = "set_action_verb_look" +const ACTION_SET_VERB_PULL = "set_action_verb_pull" +const ACTION_SET_VERB_GIVE = "set_action_verb_give" +const ACTION_SET_VERB_USE = "set_action_verb_use" +const ACTION_SET_VERB_TALK = "set_action_verb_talk" + +""" +The keyboard shortcuts are chosen to match the geometric layout in the +9verb UI (example below assumes QWERTY, but implementation should work +for non-QWERTY, as well): + +``` +open | pickup | push -> Q | W | E +close | look | pull -> A | S | D +give | use | talk -> Z | X | C +``` +""" + + +# Implemented as an array of arrays rather than a dict because dict +# does not have an items() method to enumerate entries together: +# https://github.com/godotengine/godot-proposals/issues/1965 +const action_to_scancode = [ + [ACTION_SET_VERB_OPEN, KEY_Q], + [ACTION_SET_VERB_PICKUP, KEY_W], + [ACTION_SET_VERB_PUSH, KEY_E], + + [ACTION_SET_VERB_CLOSE, KEY_A], + [ACTION_SET_VERB_LOOK, KEY_S], + [ACTION_SET_VERB_PULL, KEY_D], + + [ACTION_SET_VERB_GIVE, KEY_Z], + [ACTION_SET_VERB_USE, KEY_X], + [ACTION_SET_VERB_TALK, KEY_C], +] + + +static func add_actions_to_input_map() -> void: + for entry in action_to_scancode: + var action = entry[0] + var keycode = entry[1] + var event = InputEventKey.new() + # Based on https://github.com/godotengine/godot/pull/18020, + # `physical_scancode` seems like a more appropriate property than + # `scancode` in order to support non-QWERTY keyboard layouts while + # preserving the geometric pattern of the shortcuts. + event.physical_keycode = keycode + InputMap.add_action(action) + InputMap.action_add_event(action, event) + + +static func erase_actions_from_input_map() -> void: + for entry in action_to_scancode: + var action = entry[0] + InputMap.action_erase_events(action) + InputMap.erase_action(action) |
