X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new2%2Fplomrogue%2Fgame.py;h=2d71ac3e5089beec9117ad84dd20513f6d06d9bc;hb=40681bd38201ef0caf64a979c97318b090f5cbc0;hp=55f7c726a9020f07850e6dcb80c094c4481d8841;hpb=a213ed788c8f305ea9c2192eabfb0d3562c8b2fa;p=plomrogue2-experiments diff --git a/new2/plomrogue/game.py b/new2/plomrogue/game.py index 55f7c72..2d71ac3 100755 --- a/new2/plomrogue/game.py +++ b/new2/plomrogue/game.py @@ -1,8 +1,9 @@ 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_TURN, cmd_MAP_LINE, cmd_MAP, cmd_GET_ANNOTATION, + cmd_ANNOTATE, cmd_GET_GAMESTATE) from plomrogue.io import GameIO from plomrogue.misc import quote from plomrogue.things import Thing, ThingPlayer @@ -48,11 +49,16 @@ class Game(GameBase): 'LOGIN': cmd_LOGIN, 'TURN': cmd_TURN, 'MAP_LINE': cmd_MAP_LINE, + 'GET_ANNOTATION': cmd_GET_ANNOTATION, + 'GET_GAMESTATE': cmd_GET_GAMESTATE, + 'ANNOTATE': cmd_ANNOTATE, + 'MAP': cmd_MAP, 'PING': cmd_PING} self.thing_type = Thing self.thing_types = {'player': ThingPlayer} self.sessions = {} self.map = Map(self.map_geometry.size) + self.annotations = {} if os.path.exists(self.io.save_file): if not os.path.isfile(self.io.save_file): raise GameError('save file path refers to non-file') @@ -62,7 +68,7 @@ class Game(GameBase): for i in range(len(lines)): line = lines[i] print("FILE INPUT LINE %5s: %s" % (i, line), end='') - self.io.handle_input(line) + self.io.handle_input(line, god_mode=True) def get_string_options(self, string_option_type): import string @@ -70,7 +76,7 @@ class Game(GameBase): return self.map_geometry.get_directions() if string_option_type == 'char': return [c for c in - string.digits + string.ascii_letters + string.punctuation] + string.digits + string.ascii_letters + string.punctuation + ' '] return None def send_gamestate(self, connection_id=None): @@ -103,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() @@ -159,5 +169,13 @@ class Game(GameBase): with open(self.io.save_file, 'w') as f: write(f, 'TURN %s' % self.turn) + write(f, 'MAP %s' % (self.map_geometry.size,)) for y, line in self.map.lines(): write(f, 'MAP_LINE %5s %s' % (y, quote(line))) + for yx in self.annotations: + write(f, 'ANNOTATE %s %s' % (yx, quote(self.annotations[yx]))) + + def new_world(self, size): + self.map_geometry = MapGeometrySquare(YX(size.y, size.x)) + self.map = Map(self.map_geometry.size) + self.annotations = {}