X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomrogue-server.py;h=4cb138a3a6da7b2af8b11fa80b84b6dc784d653f;hb=7c9c3b3cc0044de265b845eec1a71d9bc3577105;hp=40cb299a05f1c2e8bab006d0489e09284e75ebbd;hpb=d87585beaacf5ad82f661cc577d3dfbeedfde398;p=plomrogue diff --git a/plomrogue-server.py b/plomrogue-server.py index 40cb299..4cb138a 100755 --- a/plomrogue-server.py +++ b/plomrogue-server.py @@ -117,20 +117,22 @@ 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(). - # How to handle strings that contain ' or "? + """Save all commands needed to reconstruct current world state.""" + # TODO: Misses same optimizations as record() from the original record(). + + def quote(string): + string = string.replace("\u005C", '\u005C\u005C') + return '"' + string.replace('"', '\u005C"') + '"' def mapsetter(key): def helper(id): string = "" if world_db["Things"][id][key]: - memmap = world_db["Things"][id][key] + rmap = world_db["Things"][id][key] length = world_db["MAP_LENGTH"] for i in range(world_db["MAP_LENGTH"]): - string = string + key + " " + str(i) + " '" + \ - memmap[i * length:(i * length) + length].decode() \ - + "'\n" + line = rmap[i * length:(i * length) + length].decode() + string = string + key + " " + str(i) + quote(line) + "\n" return string return helper @@ -148,7 +150,7 @@ def save_world(): for key in world_db[category][id]: if not key in special_keys: x = world_db[category][id][key] - argument = "'" + x + "'" if str == type(x) else str(x) + argument = quote(x) if str == type(x) else str(x) string = string + key + " " + argument + "\n" elif special_keys[key]: string = string + special_keys[key](id) @@ -289,8 +291,8 @@ def play_game(): def remake_map(): - # DUMMY. - print("I'd (re-)make the map now, if only I knew how.") + # DUMMY map creator. + world_db["MAP"] = bytearray(b'.' * (world_db["MAP_LENGTH"] ** 2)) def set_world_inactive(): @@ -367,7 +369,8 @@ def command_makeworld(seed_string): def command_maplength(maplength_string): # DUMMY. set_world_inactive() - # TODO: remove things, map + # TODO: remove map + world_db["Things"] = {} setter(None, "MAP_LENGTH", 1, 256)(maplength_string) @@ -504,6 +507,9 @@ def command_tcarries(str_int): world_db["Things"][val]["carried"] = True else: print("Ignoring: Thing not available for carrying.") + # Note that the whole carrying structure is different from the C version: + # Carried-ness is marked by a "carried" flag, not by Things containing + # Things internally. @test_Thing_id