diff options
| author | troido <troido@protonmail.com> | 2019-01-18 17:59:45 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2019-01-18 17:59:45 +0100 |
| commit | 01399d4be6f3dacb7c0bed2b84edbbc63331b83e (patch) | |
| tree | b0293a505158c6a537ee75320469cc335de07b89 | |
| parent | b4cb3cf82337c5a0d560fd77c9a921298b07aa21 (diff) | |
config templates are now actually used
| -rw-r--r-- | asciifarm/client/commandhandler.py | 19 | ||||
| -rw-r--r-- | asciifarm/client/inputhandler.py | 5 | ||||
| -rw-r--r-- | asciifarm/client/loaders.py | 4 | ||||
| -rw-r--r-- | asciifarm/keybindings/azerty.json | 57 |
4 files changed, 27 insertions, 58 deletions
diff --git a/asciifarm/client/commandhandler.py b/asciifarm/client/commandhandler.py index db9f625..ca72b68 100644 --- a/asciifarm/client/commandhandler.py +++ b/asciifarm/client/commandhandler.py @@ -51,17 +51,16 @@ class CommandHandler: } def execute(self, action): - try: - if isinstance(action[0], str): - command = action[0] - if command in self.commands: - self.commands[command](*action[1:]) - else: - raise InvalidCommandException("Invalid command '{}'".format(command)) + if action is None: + return + if isinstance(action[0], str): + command = action[0] + if command in self.commands: + self.commands[command](*action[1:]) else: - raise Exception("Command should be a string") - except Exception as e: - self.log(e) + raise InvalidCommandException("Invalid command '{}'".format(command)) + else: + raise Exception("Command should be a string") # Commands diff --git a/asciifarm/client/inputhandler.py b/asciifarm/client/inputhandler.py index 8d99c40..850e890 100644 --- a/asciifarm/client/inputhandler.py +++ b/asciifarm/client/inputhandler.py @@ -35,7 +35,10 @@ class InputHandler: else: try: command, _sep, arg = message[1:].partition(' ') - self.commandHandler.execute([command, arg]) + try: + self.commandHandler.execute([command, arg]) + except Exception as e: + self.log(e) except InvalidCommandException as e: self.client.log(", ".join(e.args)) else: diff --git a/asciifarm/client/loaders.py b/asciifarm/client/loaders.py index 0b4c5b7..8330e0e 100644 --- a/asciifarm/client/loaders.py +++ b/asciifarm/client/loaders.py @@ -23,7 +23,7 @@ def loadKeybindings(name): for ftemplate in data.get("templates", []): if ftemplate.partition(os.sep)[0] in {".", ".."}: ftemplate = os.path.relpath(ftemplate, fname) - template = loadKeyBindings(ftemplate) + template = loadKeybindings(ftemplate) bindings.update(template.get("actions", {})) help = template.get("help", help) bindings.update(data.get("actions", {})) @@ -31,7 +31,7 @@ def loadKeybindings(name): return {"actions": bindings, "help": help} -standardCharFiles = {name, os.path.join(charmapPath, file) for name, file in { +standardCharFiles = {name: os.path.join(charmapPath, file) for name, file in { "default": "default.json", "fullwith": "fullwidth.json", "fw": "fullwidth.json", diff --git a/asciifarm/keybindings/azerty.json b/asciifarm/keybindings/azerty.json index 547a181..ee04ec5 100644 --- a/asciifarm/keybindings/azerty.json +++ b/asciifarm/keybindings/azerty.json @@ -1,47 +1,14 @@ { -"actions": { -"z": ["move", "north"], -"s": ["move", "south"], -"d": ["move", "east"], -"q": ["move", "west"], -"KEY_UP": ["move", "north"], -"KEY_DOWN": ["move", "south"], -"KEY_RIGHT": ["move", "east"], -"KEY_LEFT": ["move", "west"], -"k": ["move", "north"], -"j": ["move", "south"], -"l": ["move", "east"], -"h": ["move", "west"], -"e": ["inputwithselected", "take", "ground"], -"a": ["inputwithselected", "drop", "inventory"], -"E": ["inputwithselected", "use", "inventory"], -"w": ["inputwithselected", "unequip", "equipment"], -"R": ["input", ["interact"]], -"r": ["do", [ - ["input", ["interact"]], - ["input", ["interact", "north"]], - ["input", ["interact", "south"]], - ["input", ["interact", "east"]], - ["input", ["interact", "west"]]]], -"c": ["select", "inventory", 1, true, true], -"x": ["select", "ground", 1, true, true], -"v": ["select", "equipment", 1, true, true], -"f": ["do", [ - ["input", ["attack"]], - ["input", ["attack", "north"]], - ["input", ["attack", "south"]], - ["input", ["attack", "east"]], - ["input", ["attack", "west"]]]], -"F": ["input", ["attack"]], -"Z": ["input", ["attack", "north"]], -"S": ["input", ["attack", "south"]], -"D": ["input", ["attack", "east"]], -"Q": ["input", ["attack", "west"]], -"t": ["runinput"], -"NEWLINE": ["runinput"], -"KEY_PPAGE": ["scrollchat", 1], -"KEY_NPAGE": ["scrollchat", -1], -"/": ["runinput", "/"] -}, -"help": "Controls:\n zqsd or arrows:\n Move around\n e: Grab\n q: Drop\n E: Use/Equip\n r: Interact\n f: Attack\n t: Chat\n w: Unequip\n xcv: scroll\n ctrl-c: close client" + "templates": ["default"], + "actions": { + "z": ["move", "north"], + "w": null, + "W": null, + "q": ["move", "west"], + "a": ["unuse"], + "A": ["take"], + "Z": ["input", ["attack", "north"]], + "Q": ["input", ["attack", "west"]] + }, + "help": "Controls:\n aqsd or arrows:\n Move around\n e: Grab\n q: Drop/unequip\n selected\n r: Interact\n f: Attack\n t: Chat\n E: Use selected\n A: Take selected\n xc: select item\n vb: select menu\n ctrl-c: close client" } |
