wynnbuilder-forked-for-changes/py_script/atree-generateID.py

43 lines
1.8 KiB
Python
Raw Normal View History

"""
Generate a minified JSON Ability Tree [atree_constants_min.json] AND a minified .js form [atree_constants_min.js] of the Ability Tree with:
- All references replaced by numerical IDs
2022-06-27 09:23:22 +00:00
- Extra JSON File with Class: [Original name as key and Assigned IDs as value].
given [atree_constants.js] .js form of the Ability Tree with reference as string.
"""
import json
abilDict = {}
with open("atree_constants.js") as f:
data = f.read()
data = data.replace("const atrees = ", "")
data = json.loads(data)
for classType, info in data.items():
2022-06-27 09:23:22 +00:00
_id = 0
abilDict[classType] = {}
for abil in info:
2022-06-27 09:23:22 +00:00
abilDict[classType][abil["display_name"]] = _id
_id += 1
2022-06-27 09:23:22 +00:00
with open("atree_ids.json", "w", encoding='utf-8') as id_dest:
json.dump(abilDict, id_dest, ensure_ascii=False, indent=4)
for classType, info in data.items():
for abil in range(len(info)):
2022-06-27 09:23:22 +00:00
info[abil]["id"] = abilDict[classType][info[abil]["display_name"]]
for ref in range(len(info[abil]["parents"])):
2022-06-27 09:23:22 +00:00
info[abil]["parents"][ref] = abilDict[classType][info[abil]["parents"][ref]]
for ref in range(len(info[abil]["dependencies"])):
2022-06-27 09:23:22 +00:00
info[abil]["dependencies"][ref] = abilDict[classType][info[abil]["dependencies"][ref]]
for ref in range(len(info[abil]["blockers"])):
2022-06-27 09:23:22 +00:00
info[abil]["blockers"][ref] = abilDict[classType][info[abil]["blockers"][ref]]
data_str = json.dumps(data, ensure_ascii=False, separators=(',', ':'))
data_str = "const atrees=" + data_str
with open('atree_constants_min.js', 'w', encoding='utf-8') as abil_dest:
abil_dest.write(data_str)
with open('atree_constants_min.json', 'w', encoding='utf-8') as json_dest:
json.dump(data, json_dest, ensure_ascii=False, separators=(',', ':'))