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()
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):
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.")
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,
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
}