From e5c2205bd5176bf4e3cfc6ac0bc9adb7ff2fd4e5 Mon Sep 17 00:00:00 2001 From: reschan Date: Sat, 25 Jun 2022 22:03:03 +0700 Subject: [PATCH] add script to convert string reference to numerical id for atree d ata --- py_script/atree-generateID.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 py_script/atree-generateID.py diff --git a/py_script/atree-generateID.py b/py_script/atree-generateID.py new file mode 100644 index 0000000..4355e72 --- /dev/null +++ b/py_script/atree-generateID.py @@ -0,0 +1,35 @@ +""" +Generate a JSON Ability Tree with: + - All references replaced by numerical IDs + - Extra JSON File with Original name as key and Assigned IDs as value. +given a JSON Ability Tree. +""" +import json + +id = 0 +abilDict = {} +with open("atree-parse.json") as f: + data = json.loads(f.read()) + for classType, info in data.items(): + for abil in info: + abilDict[abil["display_name"]] = id + id += 1 + + 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)): + info[abil]["id"] = abilDict[info[abil]["display_name"]] + for ref in range(len(info[abil]["parents"])): + info[abil]["parents"][ref] = abilDict[info[abil]["parents"][ref]] + + for ref in range(len(info[abil]["dependencies"])): + info[abil]["dependencies"][ref] = abilDict[info[abil]["dependencies"][ref]] + + for ref in range(len(info[abil]["blockers"])): + info[abil]["blockers"][ref] = abilDict[info[abil]["blockers"][ref]] + data[classType] = info + + with open('atree-constants-id.json', 'w', encoding='utf-8') as abil_dest: + json.dump(data, abil_dest, ensure_ascii=False, indent=4)