-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customizable keybindings #1979
Customizable keybindings #1979
Conversation
It works! 🥳 Add an INI file: $ cat /Users/xsebek/.config/swarm/config.ini
[keybindings]
debug CESK = Ctrl-u Print the changed keybindings: cabal run -O0 swarm -- keybindings --markdown OutputKeybindingsmain
repl
The configuration file is at: |
2a128b9
to
348f088
Compare
After a lot of shuffling code back and forth, the main game handlers are customizable: OutputKeybindingsmain
repl
world
robot
|
@byorgey @kostmo, While this is not finished yet, I would appreciate it if you could test this out. The original code could have behaved differently because the conditions allowed events to be handled by subhandlers. If we really want that behavior, then those handlers have to stay in the old not-as-declarative code. By the way, this refactoring makes the Controller significantly smaller:
It is necessary because the handlers are stored in the Model, which is imported into the Controller, and a cycle would form. |
Just some small initial feeback: so far I'm just trying it out without having looked at the code yet (since that's what players will do). I found |
@byorgey, exactly. The INI file looks like that, with Event Names as keys and values being parsed by I think showing by example will be much clearer than trying to explain the format in detail. 🙂 |
I accidentally wrote a keybinding in uppercase, like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at absolutely all the code yet, but so far it seems to work great. I was able to remap the key shortcuts for the four panels which is something I have wanted for a very long time. 😁
Agreed, I think generating an initial |
By the way, key shortcuts are shown in two places in the UI: in the bar between the REPL and world panels, and also in the F1 help modal. I think in the F1 modal we should mention something about how to customize keybindings. |
I just discovered a regression: on |
@byorgey I tried setting Esc as alternative to Ctrl-C to cancel running computation. Does Ctrl-C break the game on main? |
Aha, it does! So this is not your fault. I've created #2007. |
6ac15fa
to
5d7edf0
Compare
I think the custom keybindings are now ready. 😁 @byorgey @kostmo and anyone else interested, please give this a try. I would also welcome your code review. There is not that much new code; it was mostly just moved from Controller.
@jtdaugherty has promptly fixed uppercase keybindings parsing. You can test that, too, with Brick |
Nice!! |
The keybinding case normalization fix is now released in |
data WorldEvent | ||
= ViewBaseEvent | ||
| ShowFpsEvent | ||
| MoveViewNorthEvent | ||
| MoveViewEastEvent | ||
| MoveViewSouthEvent | ||
| MoveViewWestEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can simplify some code that is cardinal-direction-specific:
data WorldEvent | |
= ViewBaseEvent | |
| ShowFpsEvent | |
| MoveViewNorthEvent | |
| MoveViewEastEvent | |
| MoveViewSouthEvent | |
| MoveViewWestEvent | |
data WorldEvent | |
= ViewBaseEvent | |
| ShowFpsEvent | |
| MoveViewDirectionEvent AbsoluteDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me handwrite Enum
and Bounded
and add a few imports, but I admit I wanted to do this too.
The usage becomes much more elegant, I just wish Haskell supported this out of the box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked about this on Discourse, and got some good suggestions:
universeGeneric
from theuniverse
package- the
finitary
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kostmo; there are some good tips in that discussion. 👍
I think I was considering finitary
before, but there was not as much need. Did not know about universeGeneric
.
I will split that as a separate Refactoring Issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! Thanks for the hard work on this really nice feature.
@xsebek I assume you were already going to do this, but just to be sure, before merging we should make sure to allow |
SwarmEvent
enumerationswarmEvents
)defaultSwarmBindings
)KeyConfig
andKeyDispatcher
s toAppState
onEvent
handleKey
with handlersmainHandler
and the rest)keybinding --init
) with commented-out (;
) settingsbrick
version 2.4 to get uppercase keybindings fix