From: Christian Heller Date: Sat, 7 Nov 2020 20:28:35 +0000 (+0100) Subject: Make keybindings configurable. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/day_todos?a=commitdiff_plain;h=29930c6b44e4b1d5b60446c0b83059588a9e2d9e;p=plomrogue2-experiments Make keybindings configurable. --- diff --git a/new2/rogue_chat_curses.py b/new2/rogue_chat_curses.py index 5b3a7a8..bb3dac2 100755 --- a/new2/rogue_chat_curses.py +++ b/new2/rogue_chat_curses.py @@ -48,19 +48,19 @@ def cmd_MAP(game, geometry, size, content): game.map_content = content if type(game.map_geometry) == MapGeometrySquare: game.tui.movement_keys = { - 'w': 'UP', - 'a': 'LEFT', - 's': 'DOWN', - 'd': 'RIGHT', + game.tui.keys['square_move_up']: 'UP', + game.tui.keys['square_move_left']: 'LEFT', + game.tui.keys['square_move_down']: 'DOWN', + game.tui.keys['square_move_right']: 'RIGHT', } elif type(game.map_geometry) == MapGeometryHex: game.tui.movement_keys = { - 'w': 'UPLEFT', - 'e': 'UPRIGHT', - 'd': 'RIGHT', - 'c': 'DOWNRIGHT', - 'x': 'DOWNLEFT', - 's': 'LEFT', + game.tui.keys['hex_move_upleft']: 'UPLEFT', + game.tui.keys['hex_move_upright']: 'UPRIGHT', + game.tui.keys['hex_move_right']: 'RIGHT', + game.tui.keys['hex_move_downright']: 'DOWNRIGHT', + game.tui.keys['hex_move_downleft']: 'DOWNLEFT', + game.tui.keys['hex_move_left']: 'LEFT', } cmd_MAP.argtypes = 'string:map_geometry yx_tuple:pos string' @@ -153,6 +153,8 @@ class TUI: self.is_intro = is_intro def __init__(self, host, port): + import os + import json self.host = host self.port = port self.mode_play = self.Mode('play') @@ -173,6 +175,30 @@ class TUI: self.queue = queue.Queue() self.login_name = None self.switch_mode('waiting_for_server') + self.keys = { + 'switch_to_chat': 'C', + 'switch_to_play': 'P', + 'switch_to_annotate': 'E', + 'switch_to_portal': 'p', + 'switch_to_study': '?', + 'switch_to_edit': 'E', + 'flatten': 'f', + 'hex_move_upleft': 'w', + 'hex_move_upright': 'e', + 'hex_move_right': 'd', + 'hex_move_downright': 'c', + 'hex_move_downleft': 'x', + 'hex_move_left': 's', + 'square_move_up': 'w', + 'square_move_left': 'a', + 'square_move_down': 's', + 'square_move_right': 'd', + } + if os.path.isfile('config.json'): + with open('config.json', 'r') as f: + keys_conf = json.loads(f.read()) + for k in keys_conf: + self.keys[k] = keys_conf[k] curses.wrapper(self.loop) def flash(self): @@ -225,18 +251,15 @@ class TUI: self.log_msg(" /P or /play - switch to play mode"); self.log_msg(" /? or /study - switch to study mode"); self.log_msg("commands common to study and play mode:"); - if type(self.game.map_geometry) == MapGeometrySquare: - self.log_msg(" w,a,s,d - move"); - elif type(self.game.map_geometry) == MapGeometryHex: - self.log_msg(" e,d,c,x,s,w - move"); - self.log_msg(" C - switch to chat mode"); + self.log_msg(" %s - move" % ','.join(self.movement_keys)); + self.log_msg(" %s - switch to chat mode" % self.keys['switch_to_chat']); self.log_msg("commands specific to play mode:"); - self.log_msg(" E - write following ASCII character"); - self.log_msg(" f - flatten surroundings"); - self.log_msg(" ? - switch to study mode"); + self.log_msg(" %s - write following ASCII character" % self.keys['switch_to_edit']); + self.log_msg(" %s - flatten surroundings" % self.keys['flatten']); + self.log_msg(" %s - switch to study mode" % self.keys['switch_to_study']); self.log_msg("commands specific to study mode:"); - self.log_msg(" E - annotate terrain"); - self.log_msg(" P - switch to play mode"); + self.log_msg(" %s - annotate terrain" % self.keys['switch_to_annotate']); + self.log_msg(" %s - switch to play mode" % self.keys['switch_to_play']); def loop(self, stdscr): @@ -504,24 +527,24 @@ class TUI: self.switch_mode('play') self.input_ = '' elif self.mode == self.mode_study: - if key == 'C': + if key == self.keys['switch_to_chat']: self.switch_mode('chat') - elif key == 'P': + elif key == self.keys['switch_to_play']: self.switch_mode('play') - elif key == 'A': + elif key == self.keys['switch_to_annotate']: self.switch_mode('annotate', keep_position=True) - elif key == 'p': + elif key == self.keys['switch_to_portal']: self.switch_mode('portal', keep_position=True) elif key in self.movement_keys: move_explorer(self.movement_keys[key]) elif self.mode == self.mode_play: - if key == 'C': + if key == self.keys['switch_to_chat']: self.switch_mode('chat') - elif key == '?': + elif key == self.keys['switch_to_study']: self.switch_mode('study') - if key == 'E': + if key == self.keys['switch_to_edit']: self.switch_mode('edit') - elif key == 'f': + elif key == self.keys['flatten']: self.send('TASK:FLATTEN_SURROUNDINGS') elif key in self.movement_keys: self.send('TASK:MOVE ' + self.movement_keys[key]) diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index b81dcb1..0f502ed 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -4,25 +4,54 @@
-movement: rows: cols: - - -

 
+
+keys:
+square_move_up: (hint: ArrowUp)
+square_move_left: (hint: ArrowLeft)
+square_move_down: (hint: ArrowDown)
+square_move_right: (hint: ArrowRight)
+hex_move_upleft:
+hex_move_upright:
+hex_move_right:
+hex_move_downright:
+hex_move_downleft:
+hex_move_left:
+flatten_:
+switch_to_chat:
+switch_to_play:
+switch_to_annotate:
+switch_to_portal:
+switch_to_study:
+switch_to_edit:
+