From: Christian Heller Date: Tue, 10 Nov 2020 00:59:35 +0000 (+0100) Subject: Add TASK command to request available commands. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/day_todos?a=commitdiff_plain;h=8c5624db0c2b463a490a425fc0f8baf2761d7d23;p=plomrogue2 Add TASK command to request available commands. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index c2484bf..e75cbe9 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -4,6 +4,11 @@ from plomrogue.mapping import YX, MapGeometrySquare, MapGeometryHex +def cmd_TASKS(game, connection_id): + tasks = [] + game.io.send('TASKS ' + ','.join(game.tasks.keys()), connection_id) +cmd_TASKS.argtypes = '' + def cmd_ALL(game, msg, connection_id): if not connection_id in game.sessions: raise GameError('need to be logged in for this') diff --git a/rogue_chat.py b/rogue_chat.py index 0b1ea23..d2e4117 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -4,7 +4,8 @@ from plomrogue.io_websocket import PlomWebSocketServer from plomrogue.io_tcp import PlomTCPServer from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_QUERY, cmd_PING, cmd_MAP, cmd_TURN, cmd_MAP_LINE, cmd_GET_ANNOTATION, - cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE) + cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE, + cmd_TASKS) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_FLATTEN_SURROUNDINGS) import sys @@ -25,6 +26,7 @@ game.register_command(cmd_GET_ANNOTATION) game.register_command(cmd_ANNOTATE) game.register_command(cmd_PORTAL) game.register_command(cmd_GET_GAMESTATE) +game.register_command(cmd_TASKS) game.register_task(Task_WAIT) game.register_task(Task_MOVE) game.register_task(Task_WRITE) diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 01e6dc3..64eaf03 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -143,6 +143,10 @@ def cmd_ANNOTATION(game, position, msg): game.tui.do_refresh = True cmd_ANNOTATION.argtypes = 'yx_tuple:nonneg string' +def cmd_TASKS(game, tasks_comma_separated): + game.tasks = tasks_comma_separated.split(',') +cmd_TASKS.argtypes = 'string' + def cmd_PONG(game): pass cmd_PONG.argtypes = '' @@ -150,6 +154,7 @@ cmd_PONG.argtypes = '' class Game(GameBase): thing_type = ThingBase turn_complete = False + tasks = {} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -167,6 +172,7 @@ class Game(GameBase): self.register_command(cmd_ARGUMENT_ERROR) self.register_command(cmd_GAME_ERROR) self.register_command(cmd_PLAY_ERROR) + self.register_command(cmd_TASKS) self.map_content = '' self.player_id = -1 self.info_db = {} @@ -293,13 +299,18 @@ class TUI: self.log_msg(" /%s or /play - switch to play mode" % self.keys['switch_to_play']); self.log_msg(" /%s or /study - switch to study mode" % self.keys['switch_to_study']); self.log_msg("commands common to study and play mode:"); - self.log_msg(" %s - move" % ','.join(self.movement_keys)); + if 'MOVE' in self.game.tasks: + 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(" %s - write following ASCII character" % self.keys['switch_to_edit']); - self.log_msg(" %s - flatten surroundings" % self.keys['flatten']); + if 'WRITE' in self.game.tasks: + self.log_msg(" %s - write following ASCII character" % self.keys['switch_to_edit']); + if 'FLATTEN_SURROUNDINGS' in self.game.tasks: + 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:"); + if 'MOVE' not in self.game.tasks: + self.log_msg(" %s - move" % ','.join(self.movement_keys)); self.log_msg(" %s - annotate terrain" % self.keys['switch_to_annotate']); self.log_msg(" %s - switch to play mode" % self.keys['switch_to_play']); @@ -334,6 +345,7 @@ class TUI: self.socket = socket_client_class(handle_recv, self.host) self.socket_thread = threading.Thread(target=self.socket.run) self.socket_thread.start() + self.socket.send('TASKS') self.switch_mode('login') return except ConnectionRefusedError: @@ -600,11 +612,13 @@ class TUI: self.switch_mode('chat') elif key == self.keys['switch_to_study']: self.switch_mode('study') - if key == self.keys['switch_to_edit']: + if key == self.keys['switch_to_edit'] and\ + 'WRITE' in self.game.tasks: self.switch_mode('edit') - elif key == self.keys['flatten']: + elif key == self.keys['flatten'] and\ + 'FLATTEN_SURROUNDINGS' in self.game.tasks: self.send('TASK:FLATTEN_SURROUNDINGS') - elif key in self.movement_keys: + elif key in self.movement_keys and 'MOVE' in self.game.tasks: self.send('TASK:MOVE ' + self.movement_keys[key]) elif self.mode == self.mode_edit: self.send('TASK:WRITE ' + key) diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index c01f7ab..4adb4ee 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -173,6 +173,7 @@ let server = { this.websocket = new WebSocket(this.url); this.websocket.onopen = function(event) { window.setInterval(function() { server.send(['PING']) }, 30000); + this.send('TASKS'); tui.log_msg("@ server connected! :)"); tui.switch_mode(mode_login); }; @@ -203,6 +204,8 @@ let server = { game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]); } else if (tokens[0] === 'THING_NAME') { game.get_thing(tokens[1], true).name_ = tokens[2]; + } else if (tokens[0] === 'TASKS') { + game.tasks = tokens[1].split(',') } else if (tokens[0] === 'MAP') { game.map_geometry = tokens[1]; tui.init_keys(); @@ -411,13 +414,22 @@ let tui = { this.log_msg(" /" + this.keys.switch_to_play + " or /play - switch to play mode"); this.log_msg(" /" + this.keys.switch_to_study + " or /study - switch to study mode"); this.log_msg("commands common to study and play mode:"); - this.log_msg(" " + movement_keys_desc + " - move"); + if (game.tasks.includes('MOVE')) { + this.log_msg(" " + movement_keys_desc + " - move"); + } this.log_msg(" " + this.keys.switch_to_chat + " - switch to chat mode"); this.log_msg("commands specific to play mode:"); - this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character"); - this.log_msg(" " + this.keys.flatten + " - flatten surroundings"); + if (game.tasks.includes('WRITE')) { + this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character"); + } + if (game.tasks.includes('FLATTEN_SURROUNDINGS')) { + this.log_msg(" " + this.keys.flatten + " - flatten surroundings"); + } this.log_msg(" " + this.keys.switch_to_study + " - switch to study mode"); this.log_msg("commands specific to study mode:"); + if (!game.tasks.includes('MOVE')) { + this.log_msg(" " + movement_keys_desc + " - move"); + } this.log_msg(" " + this.keys.switch_to_annotate + " - annotate terrain"); this.log_msg(" " + this.keys.switch_to_play + " - switch to play mode"); }, @@ -538,6 +550,7 @@ let game = { this.map_size = [0,0]; this.player_id = -1; this.portals = {}; + this.tasks = {}; }, get_thing: function(id_, create_if_not_found=false) { if (id_ in game.things) { @@ -748,14 +761,17 @@ tui.inputEl.addEventListener('keydown', (event) => { if (event.key === tui.keys.switch_to_chat) { event.preventDefault(); tui.switch_mode(mode_chat); - } else if (event.key === tui.keys.switch_to_edit) { + } else if (event.key === tui.keys.switch_to_edit + && game.tasks.includes('WRITE')) { event.preventDefault(); tui.switch_mode(mode_edit); } else if (event.key === tui.keys.switch_to_study) { tui.switch_mode(mode_study); - } else if (event.key === tui.keys.flatten) { + } else if (event.key === tui.keys.flatten + && game.tasks.includes('FLATTEN_SURROUNDINGS')) { server.send(["TASK:FLATTEN_SURROUNDINGS"]); - } else if (event.key in tui.movement_keys) { + } else if (event.key in tui.movement_keys + && game.tasks.includes('MOVE')) { server.send(['TASK:MOVE', tui.movement_keys[event.key]]); }; } else if (tui.mode == mode_study) {