From 86f6e8578591905fc7d1b53ca38b2ea776819992 Mon Sep 17 00:00:00 2001 From: Trysdyn Black Date: Sun, 30 Jun 2024 22:47:27 -0700 Subject: [PATCH] Add monster and BCCE Remonsterate support - Monster data for all versions - Remonsterate data added to MONSTERS section for BCCE with remons on --- main.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/main.py b/main.py index 8c2103b..dc459f0 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,94 @@ import json import sys +def parse_MONSTERS(data): + result = {} + for m_text in data.split("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"): + info = {"stats": {}, "spells": {}} + name = "NULL" + for line in m_text.split("\n"): + # Name and level + if "(Level " in line: + name = line.split(" (")[0] + info["stats"]["level"] = int(line.split("Level ")[1][:-1]) + # Stat chart rows + elif line.startswith("|"): + for stat in line[1:-1].split("|"): + if ":" in stat: + stat_name, stat_value = stat.split(":") + stat_name = stat_name.replace(".", "").strip().lower() + info["stats"][stat_name] = int(stat_value) + # Nullifies AND weaks, split by a ; + elif line.startswith("NULLIFY:"): + # If no weaknesses, WEAK section just doesn't appear, fudge it + if "WEAK:" in line: + null_text, weak_text = line.split(";") + else: + null_text = line + weak_text = "WEAK: " + info["nullifies"] = null_text.split(": ")[1].split(", ") + info["weak"] = weak_text.split(": ")[1].split(", ") + elif line.startswith("IMMUNE:"): + if len(line) >= 9: + info["immune"] = line.split(": ")[1].split(", ") + else: + info["immune"] = [] + elif line.startswith("AUTO:"): + if len(line) >= 7: + info["auto"] = line.split(": ")[1].split(", ") + else: + info["auto"] = [] + # Specials are name=>desc as k:v + # I *think* you can only have one special... + elif line.startswith("SPECIAL"): + content = line.split(" ", 1)[1] + if len(content) > 1: + special_name = content.split('"')[1] + special_desc = content.split(": ")[1] + info["special"] = {special_name: special_desc} + else: + info["special"] = {} + elif line.startswith("SKILLS:"): + if len(line) >= 9: + info["skills"] = line.split(": ")[1].split(", ") + info["skills"] = [] + elif line.startswith("STEAL:"): + if len(line) >= 8: + info["steal"] = line.split(": ")[1].split(", ") + else: + info["steal"] = [] + elif line.startswith("DROPS:"): + if len(line) >= 8: + info["drops"] = line.split(": ")[1].split(", ") + else: + info["drops"] = [] + elif line.startswith("LOCATION:"): + if len(line) >= 11: + info["location"] = line.split(": ", 1)[1] + else: + info["location"] = None + + if name != "NULL": + result[name] = info + + return result + + +def parse_REMONSTERATE(data): + # BCCE only. Remapping info if you use BCCE to also remonsterate + result = {} + for line in data.split("\n"): + if not line or line.startswith("-----"): + continue + name = line.split("(")[0].strip() + originally = line.split("(", 1)[1].split(")")[0].strip() + sprite = line.split("->")[1].strip().strip(".") + + result[name] = {"originally": originally, "sprite": sprite} + + return result + + def parse_CHARACTERS(data): replacements = {"Looks like": "looks", "World of Ruin location": "wor_location", "Notable equipment": "equipment"} @@ -134,6 +222,7 @@ def parse_SEED(data): def parse_SECRET_ITEMS(data): + # BCCE Only # I have no idea what this is lol, dump it to a list for now return [line for line in data.split("\n") if not line.startswith("---")] @@ -193,5 +282,15 @@ if __name__ == "__main__": c_data["stats"] = stats del data["STATS"] + # If we ran BCCE Remonsterate, fold sprite data into monster block + if "REMONSTERATE" in data: + for name, info in data["REMONSTERATE"].items(): + for m_name, m_info in data["MONSTERS"].items(): + if name == m_name: + m_info["originally"] = info["originally"] + m_info["sprite"] = info["sprite"] + + del data["REMONSTERATE"] + # Barf this pile of trash out print(json.dumps(data))