MartinHowarth / shimmer

Create games in python, without hassle - batteries included!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to save and load custom keymap to/from file.

MartinHowarth opened this issue · comments

Challenge here is that current key maps are defined with references to actual code objects.
Need to be able to refer to objects by strings instead.
I think this should JustWork™️ by adding the restriction that KeyboardActionDefinition can only have callbacks to a single object - and use getattr to find methods on that object.

i.e. interface would be:
KeyboardActionDefinition.from_yaml(target_object, yaml_defn=None)
and the equivalent to_yaml would just get the string name of the functions it points at.

And the calculator example would approximately change from def create_keymap(self) -> KeyMap: to static method: create_keymap(calculator, yaml_defn=None) -> KeyMap:

Unresolved challenge:

  • need a way to make it easy to state which object to re-load the map for.
    • For global singletons this seems pretty straightforward.
    • Alternatively, encourage / mandate that keyboardhandlers (not just KeyboardActionDefinition) must act on a single object - then the definition of a keymap is pure and contained.
    • Alternatively, because keymaps are probably identical for all things of the same type (assuming only one focused at once) then a global map of unique string: keymap save name as part of a class definition means we can re-load it for any of a given class easily. e.g. class Calculator: _keymap_name = Calculator (default to class.name? - should be unique for most situations)

Second challenge:
Actually make keymaps editable. Shouldn't be too hard to just define a collection of buttons + key captures in a menu/form layout (once those are implemented!)