diff options
| author | troido <troido@hotmail.com> | 2017-11-13 11:57:00 +0100 |
|---|---|---|
| committer | troido <troido@hotmail.com> | 2017-11-13 11:57:00 +0100 |
| commit | 336f6f873c52ef62e2f304436b381c166eac872f (patch) | |
| tree | 9206f3c8bec1673a7851a0910862ccb5c9ed7162 | |
| parent | e26a64d42870c9d45607d24a41cfb0ad037165d9 (diff) | |
used curses.keyname instead of ord. It is now possible to use non printable keys for controlling (like arrow keys)
| -rw-r--r-- | asciifarm/client/gameclient.py | 16 | ||||
| -rw-r--r-- | asciifarm/keybindings/default.json | 6 |
2 files changed, 12 insertions, 10 deletions
diff --git a/asciifarm/client/gameclient.py b/asciifarm/client/gameclient.py index 6038fec..88238d1 100644 --- a/asciifarm/client/gameclient.py +++ b/asciifarm/client/gameclient.py @@ -27,12 +27,12 @@ class Client: for key, commands in keybindings["input"].items(): if isinstance(commands[0], str): commands = [commands] - self.commands[ord(key)] = [["input", command] for command in commands] + self.commands[key] = [["input", command] for command in commands] self.controlsString = "Controls:\n"+'\n'.join( - chr(key) + ": " + ', '.join(' '.join(action[1]) for action in actions) + key + ": " + ', '.join(' '.join(action[1]) for action in actions) for key, actions in self.commands.items() - if chr(key) in string.printable) + if key in string.printable) self.display.showInfo(self.controlsString) @@ -96,10 +96,6 @@ class Client: self.display.setGround(msg[1]) if msgType == "message": self.log(msg[1]) - #self.display.addMessage(msg[1]) - #if self.logFile: - #with(open(self.logFile, 'a')) as f: - #f.write(msg[1]+'\n') self.display.update() @@ -115,8 +111,10 @@ class Client: key = self.stdscr.getch() if key == 27: self.keepalive = False - if key in self.commands: - self.connection.send(json.dumps(self.commands[key])) + return + keyname = str(curses.keyname(key), "utf-8") + if keyname in self.commands: + self.connection.send(json.dumps(self.commands[keyname])) diff --git a/asciifarm/keybindings/default.json b/asciifarm/keybindings/default.json index 270eaa9..23eaa26 100644 --- a/asciifarm/keybindings/default.json +++ b/asciifarm/keybindings/default.json @@ -13,6 +13,10 @@ "D": ["attack", "east"], "A": ["attack", "west"], "E": ["use"], - "r": ["interact"] + "r": ["interact"], + "KEY_UP": ["move", "north"], + "KEY_DOWN": ["move", "south"], + "KEY_RIGHT": ["move", "east"], + "KEY_LEFT": ["move", "west"] } } |
