-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathupdatearcanalinks.py
65 lines (49 loc) · 2 KB
/
updatearcanalinks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json
import os
from dotabase import *
# This is a script for auto-generating the arcana_links.json file
# note that to run this script you'll have to have a local version of the vpk and a parsed version of the items_game file. mine is produced as a sideproduct of running dotabase-builder
thisdir = os.path.dirname(os.path.realpath(__file__))
outfile = os.path.join(thisdir, "data/arcana_links.json")
configfile = os.path.join(thisdir, "config.json")
with open(configfile) as f:
config = json.loads(f.read())
with open(config["arcanascript"]["items_game_path"]) as f:
data = json.loads(f.read())
hero_image_cosmetics = []
# go through the cosmetics and look for all arcanas/personas where they change the image
for itemid in data["items_game"]["items"]:
item = data["items_game"]["items"][itemid]
for attr in item.get("visuals", {}):
if not ("asset_modifier" in attr):
continue
attr_data = item["visuals"][attr]
if attr_data.get("type") == "icon_replacement_hero":
image = attr_data.get("modifier")
heroname = list(item["used_by_heroes"].keys())[0]
hero_image_cosmetics.append({
"hero": heroname,
"image": image
})
elif attr_data.get("type") == "icon_replacement_hero_minimap" and "persona" in attr_data.get("modifier"):
image = attr_data.get("modifier")
heroname = list(item["used_by_heroes"].keys())[0]
hero_image_cosmetics.append({
"hero": heroname,
"image": image
})
vpk_path = config["arcanascript"]["vpk_path"]
session = dotabase_session()
output_json = {}
for image_cosmetic in hero_image_cosmetics:
hero_id = str(session.query(Hero).filter_by(full_name=image_cosmetic["hero"]).first().id)
if hero_id not in output_json:
output_json[hero_id] = []
filepath = f"/panorama/images/heroes/{image_cosmetic['image']}_png.png"
if not os.path.exists(vpk_path + filepath):
print(f"Error! Can't find file {filepath} (skipping)")
else:
output_json[hero_id].append(filepath)
with open(outfile, "w+") as f:
f.write(json.dumps(output_json, indent="\t"))
print("Done!")