pass
+class PlayError(Exception):
+ pass
+
+
class BrokenSocketConnection(Exception):
pass
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)
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()
"""
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):
# 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)))
-from plomrogue.errors import GameError
+from plomrogue.errors import PlayError
from plomrogue.mapping import YX
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()
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++) {
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++) {
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);
} 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();