-
Notifications
You must be signed in to change notification settings - Fork 7
/
gen_object_meta.py
147 lines (100 loc) · 3.17 KB
/
gen_object_meta.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
import os
import yaml
import json
import glob
def u_constrt(loader, node):
return node.value
def io_constrt(loader, node):
value = loader.construct_mapping(node)
return value
def list_constrt(loader, node):
value = loader.construct_mapping(node)
return value
def obj_constrt(loader, node):
value = loader.construct_mapping(node)
return value
def str_constrt(loader, node):
return node.value
def vec3_constrt(loader, node):
return node.value
def color_constrt(loader, node):
return node.value
yaml.add_constructor("!u", u_constrt)
yaml.add_constructor("!io", io_constrt)
yaml.add_constructor("!color", color_constrt)
yaml.add_constructor("!list", list_constrt)
yaml.add_constructor("!obj", obj_constrt)
yaml.add_constructor("!str64", str_constrt)
yaml.add_constructor("!str32", str_constrt)
yaml.add_constructor("!str256", str_constrt)
yaml.add_constructor("!vec3", vec3_constrt)
def is_npc(name):
return name.startswith("Npc_")
def is_obj(name):
return name.startswith("Obj_")
def is_item(name):
return name.startswith("Item_")
def is_horse(name):
return name.startswith("GameRomHorse")
def is_dummy(name):
return name == "Dummy"
def is_tree(name):
return name.startswith("Tree")
def is_remain_wind(name):
return name.startswith("RemainsWind")
def should_skip(name):
return (
is_npc(name)
or is_obj(name)
or is_horse(name)
or is_dummy(name)
or is_tree(name)
or is_remain_wind(name)
)
def get_value(data, names):
v = data
for name in names:
if name in v:
v = v[name]
else:
return None
return v
meta = {}
def add_meta(name, key, value):
if not name in meta:
meta[name] = {}
meta[name][key] = value
for file in glob.glob(f"Actor/ActorLink/*.yml"):
with open(file, "r") as f:
bdata = yaml.load(f, Loader=yaml.FullLoader)
name = os.path.basename(file).replace(".yml", "")
gpar = get_value(bdata, ["param_root", "objects", "LinkTarget", "GParamUser"])
if gpar == "Dummy" or gpar == "MessageOnly":
continue
with open(f"Actor/GeneralParamList/{gpar}.gparamlist.yml", "r") as f:
data = yaml.load(f, Loader=yaml.FullLoader)
enemy = get_value(data, ["param_root", "objects", "Enemy"])
weapon = get_value(data, ["param_root", "objects", "WeaponCommon"])
if not enemy and not weapon:
continue
aname = get_value(data, ["param_root", "objects", "System", "SameGroupActorName"])
if should_skip(name):
continue
life = get_value(data, ["param_root", "objects", "General", "Life"])
if "Enemy_SiteBoss" in file:
# See https://zeldamods.org/wiki/Difficulty_scaling#Ganon_Blights
if "Weapon" in file:
pass
elif "Castle" in file:
life = 2000
elif "_R" in file:
life = 1500
else:
life = "800 - 2000"
if life:
add_meta(name, "life", life)
attack = get_value(data, ["param_root", "objects", "Attack", "Power"])
if attack:
add_meta(name, "attack", attack)
json.dump(meta, open("object_meta.json", "w"))