diff --git a/main.py b/main.py index 18891a3..7d0774d 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ """Parse BCEX (or BCCE) logs into json objects.""" -__version__ = "0.3" +__version__ = "0.4.0" __author__ = "Trysdyn Black" import json @@ -126,9 +126,14 @@ def parse_CHARACTERS(data: str) -> dict[str, dict]: # noqa: C901 spell_level, spell_name = line.split("-", 1) info["spells"][spell_name.strip()] = int(spell_level.strip().split(" ")[1]) - # Special k=v strings with comma-delimited lists + # Command list + # Commands: is just a CSV list of things like "fight" "magic" etc. However if command + # randomization is on, these will be exotic things like "KitMerton" that need additional + # info provided from the COMMANDS section later. + # As such, we begin with a dehydrated hash of command_name=None, then the COMMANDS section + # will provide hydration data for the values. elif line.startswith("Commands:"): - info["commands"] = [command.strip() for command in line.split(":")[1].split(",")] + info["commands"] = {command.strip(): None for command in line.split(":")[1].split(",")} elif line.startswith("Notable"): info["equipment"] = [eq.strip() for eq in line.split(":")[1].split(",")] @@ -288,17 +293,13 @@ if __name__ == "__main__": except KeyError: continue - # Subkey CHARACTERS commands with COMMANDS data - # This turns lists of commands each character has into hashes where - # Command name => Textual desc of command - # Certain flags don't shuffle commands like this so we have to check - if "COMMANDS" in data: - for c_data in data["CHARACTERS"].values(): - new_commands = {} - - for command in c_data["commands"]: - new_commands[command] = data["COMMANDS"].get(command, command) - c_data["commands"] = new_commands + # Hydrate each character's command list with descriptions of the commands + # This uses the COMMANDS section, but if one doesn't exist just repeat the command + # name because it should be simple things like "fight" and "magic" + command_info = data.get("COMMANDS", {}) + for c_data in data["CHARACTERS"].values(): + for command in c_data["commands"]: + c_data["commands"][command] = command_info.get(command, command) # If we have a STATS block, snap it into CHARACTER data # BCCE broke this out into its own section