feat(input): remove fixed keyboard controls from GameOptions - #655
feat(input): remove fixed keyboard controls from GameOptions#655BenjaminAmos wants to merge 1 commit into
Conversation
NicholasBatesNZ
left a comment
There was a problem hiding this comment.
Had a proper read of this — it's a nice cleanup, and it quietly fixes the fact that keyMercenaryInteraction and keyFreeCameraMovement were never being written to settings.ini at all. I diffed all 23 defaults against the old DEFAULT_* constants and they're identical, existing settings files still load fine, there are no leftover references, and it compiles clean on the new Gradle 9.6.1 / Java 17 setup.
One thing I'd like fixed before merge: Input.Keys.valueOf returns -1 for an unrecognised name and that -1 now gets stored in the map, so Input.Keys.toString(-1) later throws IllegalArgumentException — a corrupt or hand-edited settings.ini now crashes on save or on opening the Controls menu, where before it just degraded. A if (key < 0) fallback to getDefaultInputs() in parseKeyboardControl should do it.
Minor extras: MERCENARY_INTERACTION's display name says "Hire Ship", and using an EnumMap instead of HashMap would stop the ini key order reshuffling on every save.
Description
This pull request moves the input control constants from
GameOptionsinto a separateDefaultOptionsenum.GameOptionshas been changed to instead use a dynamic map of controls to their triggering inputs. This should allow for greater extensibility in the future, since modules can now define input controls. There is no way at present to persist the runtime-added controls yet.An input control consists of an action that can be triggered by any number of input keys. The control itself contains the constant data describing what the control is and how it can be used. Controls are now associated with input types, which can be any of
KEYBOARD,MIXED,MOUSEandCONTROLLER. Controls can be associated with multiple input types.A control can now support an arbitrary number of keys as triggering inputs. This is implemented internally within
GameOptionsbut currently nothing in the game supports it. Changing the input bindings from the main menu will replace all existing bindings for that control with the single binding chosen currently.Testing
Future Improvements
These changes are not happening in this pull request but would be ideal as follow-ups.
Notes