Make character command data consistent typing
Previously a character's command data could be a list or a dict depending on if command randomization was on. This resulted in having to inspect the object and determine its type in tools using the output. This change guarantees character command data will be a dict of name->description. The description is pulled from the COMMANDS section of the spoiler log. If it doesn't exist (or the command is not present, which should never happen), the description will simply be the command name again.
This commit is contained in:
parent
087025fdd4
commit
c782c3a79b
1 changed files with 15 additions and 14 deletions
29
main.py
29
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
|
||||
|
|
Loading…
Add table
Reference in a new issue