home · contact · privacy
Add blink screen on trivial errors instead of log messages.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 29 Oct 2020 00:41:40 +0000 (01:41 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 29 Oct 2020 00:41:40 +0000 (01:41 +0100)
new2/plomrogue/errors.py
new2/plomrogue/game.py
new2/plomrogue/io.py
new2/plomrogue/tasks.py
new2/rogue_chat_nocanvas_monochrome.html

index bc374952117312bba1462505138c36c206f0d4a9..b98f8f67114a6977d4b7f9059262306514dc9354 100644 (file)
@@ -6,5 +6,9 @@ class GameError(Exception):
     pass
 
 
+class PlayError(Exception):
+    pass
+
+
 class BrokenSocketConnection(Exception):
     pass
index e7a4262df8bffd7b44e3ba7639cefa276b545573..2d71ac3e5089beec9117ad84dd20513f6d06d9bc 100755 (executable)
@@ -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()
index 9f34b180f851793b04ce02e32c52b46ea9c68481..908d7bf504b7c304c937729b1bb5cccb3f47538b 100644 (file)
@@ -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)))
 
index 0fe68791d9ee779df2f6160a8f85bc0f2ade9dcf..bb78b98699a84ac507699074de4d45dd37237fbd 100644 (file)
@@ -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()
index e8f7873eb3794407c53747938bfe6ec2e1ecd459..096b6d55fa3f8eee0726999b57b1faa44bae5da6 100644 (file)
@@ -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();