X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=server%2Fio.py;h=ad30cc2d1fe892e1fcdf65549d6d5fadb2aad60f;hb=5cdce6d500080008b097435e2891674c16fde208;hp=a79e548cf4f359c1931ff20e11364797ab0b0d0e;hpb=c983c3c4288c671168248f7006296d7340e3d38f;p=plomrogue diff --git a/server/io.py b/server/io.py index a79e548..ad30cc2 100644 --- a/server/io.py +++ b/server/io.py @@ -167,15 +167,29 @@ def save_world(): def helper(category, id_string, special_keys={}): string = "" - for id in sorted(world_db[category].keys()): - string = string + id_string + " " + str(id) + "\n" - for key in sorted(world_db[category][id].keys()): + for _id in sorted(world_db[category].keys()): + string = string + id_string + " " + str(_id) + "\n" + for key in sorted(world_db[category][_id].keys()): if not key in special_keys: - x = world_db[category][id][key] + x = world_db[category][_id][key] argument = quote_escape(x) if str == type(x) else str(x) string = string + key + " " + argument + "\n" - elif special_keys[key]: - string = string + special_keys[key](id) + return string + + def helper_things(): + string = "" + memmap = mapsetter("T_MEMMAP") + memdepthmap = mapsetter("T_MEMDEPTHMAP") + for tid in sorted(world_db["Things"].keys()): + string += "T_ID " + str(tid) + "\n" + t = world_db["Things"][tid] + for key in sorted(t.keys()): + if key not in {"T_CARRIES", "carried", "fovmap", "T_MEMMAP", + "T_MEMTHING", "T_MEMDEPTHMAP", "pos"}: + argument = t[key] + string += key + " " + (quote_escape(argument) if \ + str == type(argument) else str(argument)) + "\n" + string += memthing(tid) + memmap(tid) + memdepthmap(tid) return string string = "" @@ -192,15 +206,11 @@ def save_world(): for id in sorted(world_db["ThingTypes"].keys()): string = string + "TT_ID " + str(id) + "\n" + "TT_CORPSE_ID " + \ str(world_db["ThingTypes"][id]["TT_CORPSE_ID"]) + "\n" - string = string + helper("Things", "T_ID", - {"T_CARRIES": False, "carried": False, - "T_MEMMAP": mapsetter("T_MEMMAP"), - "T_MEMTHING": memthing, "fovmap": False, - "T_MEMDEPTHMAP": mapsetter("T_MEMDEPTHMAP")}) - for id in sorted(world_db["Things"].keys()): - if [] != world_db["Things"][id]["T_CARRIES"]: - string = string + "T_ID " + str(id) + "\n" - for carried in sorted(world_db["Things"][id]["T_CARRIES"]): + string += helper_things() + for tid in sorted(world_db["Things"].keys()): + if [] != world_db["Things"][tid]["T_CARRIES"]: + string = string + "T_ID " + str(tid) + "\n" + for carried in sorted(world_db["Things"][tid]["T_CARRIES"]): string = string + "T_CARRIES " + str(carried) + "\n" string = string + "SEED_RANDOMNESS " + str(rand.seed) + "\n" + \ "WORLD_ACTIVE " + str(world_db["WORLD_ACTIVE"]) @@ -257,7 +267,7 @@ def obey(command, prefix, replay=False, do_record=False): if world_db["WORLD_ACTIVE"]: save_world() io_db["record_chunk"] = "" - io_db["save_wait"] = time.time() + io_db["save_wait_start"] = time.time() io_db["worldstate_updateable"] = world_db["WORLD_ACTIVE"] elif 0 != len(tokens): print("Invalid command/argument, or bad number of tokens: " + command)