2022-06-27 09:23:22 +00:00
|
|
|
"""
|
|
|
|
Generate a JSON Ability Tree [atree_constants_idfied.json] with:
|
|
|
|
- All references replaced by numerical IDs
|
|
|
|
given a JSON Ability Tree with reference as string AND a JSON Ability Names to IDs.
|
|
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
|
|
# Ability names to IDs data
|
|
|
|
with open("atree_ids.json") as f:
|
|
|
|
id_data = json.loads(f.read())
|
|
|
|
|
|
|
|
# Ability tree data with reference as string
|
|
|
|
with open("atree_constants.json") as f:
|
|
|
|
atree_data = json.loads(f.read())
|
|
|
|
|
|
|
|
for _class, info in atree_data.items():
|
2022-06-28 18:43:35 +00:00
|
|
|
def translate(path, ref):
|
|
|
|
ref_dict = info
|
|
|
|
for x in path:
|
|
|
|
ref_dict = ref_dict[x]
|
|
|
|
ref_dict[ref] = id_data[_class][ref_dict[ref]]
|
|
|
|
|
2022-06-27 09:23:22 +00:00
|
|
|
for abil in range(len(info)):
|
|
|
|
info[abil]["id"] = id_data[_class][info[abil]["display_name"]]
|
|
|
|
for ref in range(len(info[abil]["parents"])):
|
2022-06-28 18:43:35 +00:00
|
|
|
translate([abil, "parents"], ref)
|
2022-06-27 09:23:22 +00:00
|
|
|
|
|
|
|
for ref in range(len(info[abil]["dependencies"])):
|
2022-06-28 18:43:35 +00:00
|
|
|
translate([abil, "dependencies"], ref)
|
2022-06-27 09:23:22 +00:00
|
|
|
|
|
|
|
for ref in range(len(info[abil]["blockers"])):
|
2022-06-28 18:43:35 +00:00
|
|
|
translate([abil, "blockers"], ref)
|
|
|
|
|
|
|
|
if "base_abil" in info[abil]:
|
|
|
|
base_abil_name = info[abil]["base_abil"]
|
|
|
|
if base_abil_name in id_data[_class]:
|
|
|
|
translate([abil], "base_abil")
|
|
|
|
|
|
|
|
if "effects" not in info[abil]:
|
2022-06-29 07:14:40 +00:00
|
|
|
print("WARNING: abil missing 'effects' tag")
|
2022-06-28 18:43:35 +00:00
|
|
|
print(info[abil])
|
|
|
|
info[abil]["effects"] = []
|
|
|
|
for effect in info[abil]["effects"]:
|
|
|
|
if effect["type"] == "raw_stat":
|
|
|
|
for bonus in effect["bonuses"]:
|
2022-06-29 07:14:40 +00:00
|
|
|
if "abil" in bonus and bonus["abil"] in id_data[_class]:
|
2022-06-28 18:43:35 +00:00
|
|
|
bonus["abil"] = id_data[_class][bonus["abil"]]
|
|
|
|
|
|
|
|
elif effect["type"] == "stat_scaling":
|
|
|
|
if "inputs" in effect: # Might not exist for sliders
|
|
|
|
for _input in effect["inputs"]:
|
2022-06-29 07:14:40 +00:00
|
|
|
if "abil" in _input and _input["abil"] in id_data[_class]:
|
2022-06-28 18:43:35 +00:00
|
|
|
_input["abil"] = id_data[_class][_input["abil"]]
|
2022-06-29 07:14:40 +00:00
|
|
|
if isinstance(effect["output"], list):
|
|
|
|
for output in effect["outputs"]:
|
|
|
|
if "abil" in output and output["abil"] in id_data[_class]:
|
|
|
|
output["abil"] = id_data[_class][output["abil"]]
|
|
|
|
else:
|
|
|
|
if "abil" in effect["output"] and effect["output"]["abil"] in id_data[_class]:
|
|
|
|
effect["output"]["abil"] = id_data[_class][effect["output"]["abil"]]
|
2022-06-28 18:43:35 +00:00
|
|
|
|
2022-06-27 09:23:22 +00:00
|
|
|
|
|
|
|
with open('atree_constants_idfied.json', 'w', encoding='utf-8') as abil_dest:
|
2022-06-28 18:43:35 +00:00
|
|
|
json.dump(atree_data, abil_dest, ensure_ascii=False, indent=4)
|