From aa5b7c9d753f6f140d7f55d0089e6e19028031b7 Mon Sep 17 00:00:00 2001 From: troido Date: Sat, 14 Apr 2018 18:13:19 +0200 Subject: 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. --- asciifarm/client/gameclient.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'asciifarm/client/gameclient.py') 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]) -- cgit