from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE,
Task_FLATTEN_SURROUNDINGS)
from plomrogue.errors import GameError, PlayError
-from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING, cmd_MAP,
- cmd_TURN, cmd_MAP_LINE, cmd_GET_ANNOTATION,
- cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE)
from plomrogue.io import GameIO
from plomrogue.misc import quote
from plomrogue.things import Thing, ThingPlayer
self.turn = 0
self.things = []
self.map_geometry = MapGeometrySquare(YX(24, 40))
+ self.commands = {}
def get_thing(self, id_, create_unfound):
# No default for create_unfound because every call to get_thing
return t
return None
+ def register_command(self, command):
+ prefix = 'cmd_'
+ if not command.__name__.startswith(prefix):
+ raise GameError('illegal command object name: %s' % command.__name__)
+ command_name = command.__name__[len(prefix):]
+ self.commands[command_name] = command
+
+import os
class Game(GameBase):
def __init__(self, save_file, *args, **kwargs):
- import os
super().__init__(*args, **kwargs)
self.changed = True
self.io = GameIO(self, save_file)
- self.tasks = {'WAIT': Task_WAIT,
- 'MOVE': Task_MOVE,
- 'WRITE': Task_WRITE,
- 'FLATTEN_SURROUNDINGS': Task_FLATTEN_SURROUNDINGS}
- self.commands = {'QUERY': cmd_QUERY,
- 'ALL': cmd_ALL,
- 'LOGIN': cmd_LOGIN,
- 'TURN': cmd_TURN,
- 'MAP_LINE': cmd_MAP_LINE,
- 'GET_ANNOTATION': cmd_GET_ANNOTATION,
- 'PORTAL': cmd_PORTAL,
- 'GET_GAMESTATE': cmd_GET_GAMESTATE,
- 'ANNOTATE': cmd_ANNOTATE,
- 'MAP': cmd_MAP,
- 'PING': cmd_PING}
+ self.tasks = {}
self.thing_type = Thing
self.thing_types = {'player': ThingPlayer}
self.sessions = {}
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')
- else:
- with open(self.io.save_file, 'r') as f:
- lines = f.readlines()
- for i in range(len(lines)):
- line = lines[i]
- print("FILE INPUT LINE %5s: %s" % (i, line), end='')
- self.io.handle_input(line, god_mode=True)
+
+ def register_task(self, task):
+ prefix = 'Task_'
+ if not task.__name__.startswith(prefix):
+ raise GameError('illegal task object name: %s' % task.__name__)
+ task_name = task.__name__[len(prefix):]
+ self.tasks[task_name] = task
+
+ def read_savefile(self):
+ if os.path.exists(self.io.save_file):
+ with open(self.io.save_file, 'r') as f:
+ lines = f.readlines()
+ for i in range(len(lines)):
+ line = lines[i]
+ print("FILE INPUT LINE %5s: %s" % (i, line), end='')
+ self.io.handle_input(line, god_mode=True)
def get_string_options(self, string_option_type):
import string
break
if not connection_id_found:
t = self.get_thing(self.sessions[connection_id], create_unfound=False)
+ if hasattr(t, 'nickname'):
+ self.io.send('CHAT ' + quote(t.nickname + ' left the map.'))
self.things.remove(t)
to_delete += [connection_id]
for connection_id in to_delete:
f.write(msg + '\n')
with open(self.io.save_file, 'w') as f:
+ # TODO: save tasks
write(f, 'TURN %s' % self.turn)
map_geometry_shape = self.get_map_geometry_shape()
write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))