X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=new2%2Fplomrogue%2Fio.py;h=9f34b180f851793b04ce02e32c52b46ea9c68481;hb=dcb275a3ae06858ba25eee3c5cd7ab6c1d44a4df;hp=12e74500eff1b7582d2a6a81601696e8076d4833;hpb=7ea66be9de28472ea2721b9170d6fe75189a4495;p=plomrogue2-experiments diff --git a/new2/plomrogue/io.py b/new2/plomrogue/io.py index 12e7450..9f34b18 100644 --- a/new2/plomrogue/io.py +++ b/new2/plomrogue/io.py @@ -4,17 +4,18 @@ import queue class GameIO(): - def __init__(self, game): + def __init__(self, game, save_file='savefile'): from plomrogue.parser import Parser self.clients = {} self.parser = Parser(game) self.game = game + self.save_file = save_file def loop(self, q): """Handle commands coming through queue q, run game, send results back.""" while True: try: - command, connection_id = q.get(timeout=1) + command, connection_id = q.get(timeout=0.001) self.handle_input(connection_id, command) except queue.Empty: self.game.run_tick() @@ -44,8 +45,13 @@ class GameIO(): print('Killing server') self.server.server_close() - def handle_input(self, input_, connection_id=None): - """Process input_ to command grammar, call command handler if found.""" + def handle_input(self, input_, connection_id=None, god_mode=False): + """Process input_ to command grammar, call command handler if found. + + Command handlers that have no connectin_i argument in their + signature will only be called if god_mode is set. + + """ from inspect import signature from plomrogue.errors import GameError, ArgError from plomrogue.misc import quote @@ -63,7 +69,7 @@ class GameIO(): else: if 'connection_id' in list(signature(command).parameters): command(*args, connection_id=connection_id) - else: + elif god_mode: command(*args) #if store and not hasattr(command, 'dont_save'): # with open(self.game_file_name, 'a') as f: