diff options
| author | troido <troido@hotmail.com> | 2018-04-14 18:13:19 +0200 |
|---|---|---|
| committer | troido <troido@hotmail.com> | 2018-04-14 18:13:19 +0200 |
| commit | aa5b7c9d753f6f140d7f55d0089e6e19028031b7 (patch) | |
| tree | 6573cbda9383c9f12a625f95bd48bbd20cfd3f22 /asciifarm/client/gameclient.py | |
| parent | b15f89a3576b98f57ff1ec083e9299c890c1f7fc (diff) | |
Stopped using hy for keybindings
keybindings are now a JSON format.
Somehow hy errored for me, and the cleanest solution seemed not to use hy at all
Thinking about it, the client was basically loading a new interpreter to optimize something that didn't need optimizing.
It didn't make it more readable/writable either, and it always was a lot of hassle.
Diffstat (limited to 'asciifarm/client/gameclient.py')
| -rw-r--r-- | asciifarm/client/gameclient.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/asciifarm/client/gameclient.py b/asciifarm/client/gameclient.py index 9903533..69380db 100644 --- a/asciifarm/client/gameclient.py +++ b/asciifarm/client/gameclient.py @@ -12,8 +12,8 @@ from .display.screen import Screen import string from .display.display import Display -import hy -from .inputhandling import InputHandler +from .inputhandler import InputHandler +from .keynames import nameFromKey class Client: @@ -26,9 +26,9 @@ class Client: self.logFile = logFile self.inputHandler = InputHandler(self, self.display, self.connection) - self.inputHandler.readCommands(keybindings) + self.keybindings = keybindings["actions"] - self.controlsString = self.inputHandler.getDocs() + self.controlsString = keybindings.get("help", "") self.display.showInfo(self.controlsString) @@ -106,26 +106,22 @@ class Client: self.display.update() def log(self, text): + if not isinstance(text, str): + text = str(text) self.display.addMessage(text) if self.logFile: with(open(self.logFile, 'a')) as f: f.write(text+'\n') - def nameFromKey(self, keynum): # this probably belongs in inputhandler... - prenamed = { - 10: "KEY_ENTER" - } - if keynum in prenamed: - return prenamed[keynum] - return str(curses.keyname(keynum), "utf-8") - def command_loop(self): while self.keepalive: key = self.stdscr.getch() if key == 27: self.keepalive = False return - self.inputHandler.onKey(key) + keyName = nameFromKey(key) + if keyName in self.keybindings: + self.inputHandler.execute(self.keybindings[keyName]) |
