From: Christian Heller Date: Thu, 29 Oct 2020 00:41:40 +0000 (+0100) Subject: Add blink screen on trivial errors instead of log messages. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/coming?a=commitdiff_plain;h=40681bd38201ef0caf64a979c97318b090f5cbc0;p=plomrogue2-experiments Add blink screen on trivial errors instead of log messages. --- diff --git a/new2/plomrogue/errors.py b/new2/plomrogue/errors.py index bc37495..b98f8f6 100644 --- a/new2/plomrogue/errors.py +++ b/new2/plomrogue/errors.py @@ -6,5 +6,9 @@ class GameError(Exception): pass +class PlayError(Exception): + pass + + class BrokenSocketConnection(Exception): pass diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index e7a4262..2d71ac3 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -1,6 +1,6 @@ from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_FLATTEN_SURROUNDINGS) -from plomrogue.errors import GameError +from plomrogue.errors import GameError, PlayError from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING, cmd_TURN, cmd_MAP_LINE, cmd_MAP, cmd_GET_ANNOTATION, cmd_ANNOTATE, cmd_GET_GAMESTATE) @@ -109,6 +109,10 @@ class Game(GameBase): for connection_id in [c_id for c_id in self.sessions if self.sessions[c_id] == t.id_]: self.io.send('GAME_ERROR ' + quote(str(e)), connection_id) + except PlayError as e: + for connection_id in [c_id for c_id in self.sessions + if self.sessions[c_id] == t.id_]: + self.io.send('PLAY_ERROR ' + quote(str(e)), connection_id) if self.changed: self.turn += 1 self.send_gamestate() diff --git a/new2/plomrogue/io.py b/new2/plomrogue/io.py index 9f34b18..908d7bf 100644 --- a/new2/plomrogue/io.py +++ b/new2/plomrogue/io.py @@ -53,7 +53,7 @@ class GameIO(): """ from inspect import signature - from plomrogue.errors import GameError, ArgError + from plomrogue.errors import GameError, ArgError, PlayError from plomrogue.misc import quote def answer(connection_id, msg): @@ -76,6 +76,8 @@ class GameIO(): # f.write(input_ + '\n') except ArgError as e: answer(connection_id, 'ARGUMENT_ERROR ' + quote(str(e))) + except PlayError as e: + answer(connection_id, 'PLAY_ERROR ' + quote(str(e))) except GameError as e: answer(connection_id, 'GAME_ERROR ' + quote(str(e))) diff --git a/new2/plomrogue/tasks.py b/new2/plomrogue/tasks.py index 0fe6879..bb78b98 100644 --- a/new2/plomrogue/tasks.py +++ b/new2/plomrogue/tasks.py @@ -1,4 +1,4 @@ -from plomrogue.errors import GameError +from plomrogue.errors import PlayError from plomrogue.mapping import YX @@ -35,9 +35,9 @@ class Task_MOVE(Task): def check(self): test_pos = self.get_move_target() if test_pos is None: - raise GameError('would move out of map') + raise PlayError('would move out of map') elif self.thing.game.map[test_pos] != '.': - raise GameError('would move into illegal territory') + raise PlayError('would move into illegal territory') def do(self): self.thing.position = self.get_move_target() diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index e8f7873..096b6d5 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -11,8 +11,12 @@ let websocket_location = "ws://localhost:8000"; let terminal = { rows: 24, cols: 80, + foreground: 'white', + background: 'black', initialize: function() { this.pre_el = document.getElementById("terminal"); + this.pre_el.style.color = this.foreground; + this.pre_el.style.backgroundColor = this.background; this.content = []; let line = [] for (let y = 0, x = 0; y <= this.rows; x++) { @@ -28,6 +32,14 @@ let terminal = { line.push(' '); } }, + blink_screen: function() { + this.pre_el.style.color = this.background; + this.pre_el.style.backgroundColor = this.foreground; + setTimeout(() => { + this.pre_el.style.color = this.foreground; + this.pre_el.style.backgroundColor = this.background; + }, 100); + }, refresh: function() { let pre_string = ''; for (let y = 0; y < this.rows; y++) { @@ -257,8 +269,12 @@ let tui = { this.height_input = this.input_lines.length; }, shorten_input: function() { - this.input = tui.input.slice(0, -1); - this.recalc_input_lines(); + if (this.input.length == 0) { + terminal.blink_screen(); + } else { + this.input = tui.input.slice(0, -1); + this.recalc_input_lines(); + } }, draw_input: function() { terminal.drawBox(terminal.rows - this.height_input, this.window_width, this.height_input, this.window_width); @@ -385,6 +401,8 @@ server.websocket.onmessage = function (event) { } else if (tokens[0] === 'UNHANDLED_INPUT') { tui.log_msg('? unknown command'); tui.refresh(); + } else if (tokens[0] === 'PLAY_ERROR') { + terminal.blink_screen(); } else if (tokens[0] === 'ARGUMENT_ERROR') { tui.log_msg('? syntax error: ' + tokens[1]); tui.refresh();