diff --git a/main.py b/main.py index c6d0b39..2f9e06c 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ def parse_CHARACTERS(data): for c_data in data.split("\n\n")[1:-1]: info = {"stats": {}, "spells": {}, "natural_magic": False} + name = "NULL" for line in c_data.split("\n"): # Name @@ -21,6 +22,7 @@ def parse_CHARACTERS(data): name = line[4:] # Stat chart rows + # BCEX Version Only elif line.startswith("|"): for stat in line[1:-1].split("|"): if ":" in stat: @@ -47,7 +49,7 @@ def parse_CHARACTERS(data): # Everything else: normal k=v colon strings elif ":" in line: field, value = line.split(":", 1) - if field in replacements.keys(): + if field in replacements: field = replacements[field] field = field.lower() info[field] = value.strip() @@ -57,6 +59,30 @@ def parse_CHARACTERS(data): return result +def parse_STATS(data): + # BCCE Version Only + # BCCE Splits stats into its own section that we need to parse, return, then snap together + result = {} + + for c_text in data.split("\n\n"): + name = "NULL" + c_data = {} + + for line in c_text.split("\n"): + if line[0:2].isdigit(): + name = line[4:] + elif ":" not in line: + pass + else: + stat, value = line.split(":") + c_data[stat] = int(value) + + if name != "NULL": + result[name] = c_data + + return result + + def parse_COMMANDS(data): commands = {} @@ -132,11 +158,18 @@ if __name__ == "__main__": for character, c_data in data["CHARACTERS"].items(): new_commands = {} for command in c_data["commands"]: - if command in data["COMMANDS"]: - new_commands[command] = data["COMMANDS"][command] - else: - new_commands[command] = command + new_commands[command] = data["COMMANDS"].get(command, command) c_data["commands"] = new_commands + # If we have a STATS block, snap it into CHARACTER data + # BCCE broke this out into its own section + # Worse, it keys on slot name, not randomized character name + if "STATS" in data: + for slot, stats in data["STATS"].items(): + for c_name, c_data in data["CHARACTERS"].items(): + if c_data["originally"].lower() == slot.lower(): + c_data["stats"] = stats + del data["STATS"] + # Barf this pile of trash out print(json.dumps(data))