Support BCCE and its distinct STATS block
For now this just brings us to parity so a BCCE spoiler log will produce the same JSON output as a BCEX log. More testing needed on how else BCCE differs.
This commit is contained in:
parent
eb20e0561d
commit
9f7b525683
1 changed files with 38 additions and 5 deletions
43
main.py
43
main.py
|
@ -14,6 +14,7 @@ def parse_CHARACTERS(data):
|
||||||
|
|
||||||
for c_data in data.split("\n\n")[1:-1]:
|
for c_data in data.split("\n\n")[1:-1]:
|
||||||
info = {"stats": {}, "spells": {}, "natural_magic": False}
|
info = {"stats": {}, "spells": {}, "natural_magic": False}
|
||||||
|
name = "NULL"
|
||||||
|
|
||||||
for line in c_data.split("\n"):
|
for line in c_data.split("\n"):
|
||||||
# Name
|
# Name
|
||||||
|
@ -21,6 +22,7 @@ def parse_CHARACTERS(data):
|
||||||
name = line[4:]
|
name = line[4:]
|
||||||
|
|
||||||
# Stat chart rows
|
# Stat chart rows
|
||||||
|
# BCEX Version Only
|
||||||
elif line.startswith("|"):
|
elif line.startswith("|"):
|
||||||
for stat in line[1:-1].split("|"):
|
for stat in line[1:-1].split("|"):
|
||||||
if ":" in stat:
|
if ":" in stat:
|
||||||
|
@ -47,7 +49,7 @@ def parse_CHARACTERS(data):
|
||||||
# Everything else: normal k=v colon strings
|
# Everything else: normal k=v colon strings
|
||||||
elif ":" in line:
|
elif ":" in line:
|
||||||
field, value = line.split(":", 1)
|
field, value = line.split(":", 1)
|
||||||
if field in replacements.keys():
|
if field in replacements:
|
||||||
field = replacements[field]
|
field = replacements[field]
|
||||||
field = field.lower()
|
field = field.lower()
|
||||||
info[field] = value.strip()
|
info[field] = value.strip()
|
||||||
|
@ -57,6 +59,30 @@ def parse_CHARACTERS(data):
|
||||||
return result
|
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):
|
def parse_COMMANDS(data):
|
||||||
commands = {}
|
commands = {}
|
||||||
|
|
||||||
|
@ -132,11 +158,18 @@ if __name__ == "__main__":
|
||||||
for character, c_data in data["CHARACTERS"].items():
|
for character, c_data in data["CHARACTERS"].items():
|
||||||
new_commands = {}
|
new_commands = {}
|
||||||
for command in c_data["commands"]:
|
for command in c_data["commands"]:
|
||||||
if command in data["COMMANDS"]:
|
new_commands[command] = data["COMMANDS"].get(command, command)
|
||||||
new_commands[command] = data["COMMANDS"][command]
|
|
||||||
else:
|
|
||||||
new_commands[command] = command
|
|
||||||
c_data["commands"] = new_commands
|
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
|
# Barf this pile of trash out
|
||||||
print(json.dumps(data))
|
print(json.dumps(data))
|
||||||
|
|
Loading…
Add table
Reference in a new issue