-from plomrogue.tasks import Task_WAIT, Task_MOVE
+from plomrogue.tasks import Task_WAIT, Task_MOVE, Task_WRITE
from plomrogue.errors import GameError
from plomrogue.commands import cmd_ALL, cmd_LOGIN, cmd_QUERY
from plomrogue.io import GameIO
self.changed = True
self.io = GameIO(self)
self.tasks = {'WAIT': Task_WAIT,
- 'MOVE': Task_MOVE}
+ 'MOVE': Task_MOVE,
+ 'WRITE': Task_WRITE}
self.map_geometry = MapGeometrySquare(YX(24, 40))
self.commands = {'QUERY': cmd_QUERY,
'ALL': cmd_ALL,
self.map = Map(self.map_geometry.size)
def get_string_options(self, string_option_type):
+ import string
if string_option_type == 'direction':
return self.map_geometry.get_directions()
+ if string_option_type == 'char':
+ return [c for c in
+ string.digits + string.ascii_letters + string.punctuation]
return None
def send_gamestate(self, connection_id=None):
self.size = map_size
self.terrain = '.' * self.size_i
+ def __getitem__(self, yx):
+ return self.terrain[self.get_position_index(yx)]
+
+ def __setitem__(self, yx, c):
+ pos_i = self.get_position_index(yx)
+ if type(c) == str:
+ self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:]
+ else:
+ self.terrain[pos_i] = c
+
@property
def size_i(self):
return self.size.y * self.size.x
+
+ def get_position_index(self, yx):
+ return yx.y * self.size.x + yx.x
class Task_MOVE(Task):
+ todo = 1
argtypes = 'string:direction'
def get_move_target(self):
def do(self):
self.thing.position = self.get_move_target()
+
+
+
+class Task_WRITE(Task):
+ todo = 1
+ argtypes = 'string:char'
+
+ def check(self):
+ pass
+
+ def do(self):
+ self.thing.game.map[self.thing.position] = self.args[0]
let chat = {
input_line:"",
- history: ["contain whitespace, escape them with \\.",
+ history: ["visible ASCII char in the input prompt.",
+ "To write on the map, enter on a single",
+ "contain whitespace, escape them with \\.",
"Use double quotes for strings that",
"Use arrow keys to move your avatar.",
" QUERY USER TEXT - send TEXT to USER",
chat.input_line = chat.input_line.slice(0, -1);
tui.draw_input_line();
} else if (event.key === 'Enter') {
- websocket.send(chat.input_line);
- chat.input_line = ''
+ if (chat.input_line.length === 1) {
+ websocket.send("TASK:WRITE " + chat.input_line);
+ } else {
+ websocket.send(chat.input_line);
+ }
+ chat.input_line = '';
tui.draw_input_line();
} else if (event.key === 'ArrowLeft') {
websocket.send('TASK:MOVE LEFT');
} else if (event.key === 'ArrowDown') {
websocket.send('TASK:MOVE DOWN');
};
- console.log(event.key);
}, false);
let websocket = new WebSocket(websocket_location);