From: Christian Heller Date: Tue, 24 Feb 2015 01:39:53 +0000 (+0100) Subject: Server/py: Introduce TURN command into save_world(). X-Git-Tag: tce~482 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/day?a=commitdiff_plain;h=b4e6d1d9288cc3b44c7b524ddd74d2feb0e24b3d;p=plomrogue Server/py: Introduce TURN command into save_world(). --- diff --git a/plomrogue-server.py b/plomrogue-server.py index 6f51078..9e4f008 100755 --- a/plomrogue-server.py +++ b/plomrogue-server.py @@ -82,7 +82,7 @@ def obey(command, prefix, replay=False, do_record=False): else: print("Reached end of record file.") else: - commands_db[tokens[0]][2]() + commands_db[tokens[0]][2](*tokens[1:]) if do_record: record(command) save_world() @@ -119,7 +119,7 @@ def record(command): def save_world(): # Dummy for saving all commands to reconstruct current world state. # Misses same optimizations as record() from the original record(). - atomic_write(io_db["path_save"], "bla\n") + atomic_write(io_db["path_save"], "TURN " + str(world_db["TURN"]) + "\n") def obey_lines_in_file(path, name, do_record=False): @@ -234,7 +234,7 @@ def play_game(): obey(read_command(), "in file", do_record=True) -def command_makeworld(): +def command_makeworld(seed): """Mere dummy so far.""" print("I would build a whole world now if only I knew how.") @@ -250,6 +250,11 @@ def command_quit(): raise SystemExit("received QUIT command") +def command_turn(turn_string): + """Set turn to what's described in turn_string.""" + world_db["TURN"] = int(turn_string) + + """Commands database. Map command start tokens to ([0]) minimum number of expected command arguments, @@ -260,13 +265,14 @@ function to be called on it. commands_db = { "QUIT": (0, True, command_quit), "PING": (0, True, command_ping), - "MAKE_WORLD": (1, False, command_makeworld) + "MAKE_WORLD": (1, False, command_makeworld), + "TURN": (1, False, command_turn) } """World state database,""" world_db = { - "turn": 0 + "TURN": 0 }