igt-vue icon indicating copy to clipboard operation
igt-vue copied to clipboard

Implement KeyBindSetting

Open HLXII opened this issue 3 years ago • 1 comments

Currently there's no method of for players to customize their key bindings, and all key bindings would have to be hard coded.

This is some initial development for supporting player set key bindings.

A new class KeyBindSetting was created to handle this. Here we store and initialize the KeyBind that will be used. I've also updated the Settings class to include a change callback for when the setting is changed. This might be useful for custom setting handling later on, however it was necessary for the KeyBindSetting. In the change callback, we can handle removing the old KeyBind and replacing it with the new player key binding setting.

The setting UI will consist of a text input, where focusing on the element and inputting a key combination will update the setting.

Developmental Areas still lacking

  • The parseEvent static method is too simple currently, and can parse weird key bindings (pressing just the Ctrl key will result in ctrl+Control). The logic here needs to be updated to parse only valid key bindings.
  • Similarly, I've overrided the validValue method (as we don't check for default options here). This method will be a second location to validate the key binding the player has chosen (it might be possible to handle the validation in one method, though not sure how that would look). This method is currently empty, and it needs additional logic for handling validation (maybe don't allow ctrl+shift+alt?, or don't allow some key combos?).
  • This currently only supports single key bindings, so an array of key combos isn't possible with this setting.
  • The Setting UI right now is very much a piece of garbage, as I'm not good with UI/styling. Someone probably needs to look at this since I'm not familiar with tailwindcss.
  • Mousetrap documentation mentions mod as a keyword for supporting cross-platform keys. This might be an area for expanding the logic if we want to support that under the hood.
  • the Hotkeys framework currently isn't handling preventDefault or stopPropagation well, so if you have a key binding with ctrl+p, the hotkey will be handled, but the browser will also attempt to print. This might be something to look at for the Hotkey framework.

HLXII avatar Apr 03 '21 07:04 HLXII