-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_misc.py
231 lines (212 loc) · 9.38 KB
/
get_misc.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import argparse
import json
import os
import re
from util.common import text_normalization, load_text_hash_map
def get_misc(
input_path: str, map_hash_to_text: dict, output_path: str = None, max_count=-1
):
with open(input_path, "r", encoding="utf-8") as f:
items = json.load(f)
unique_set = set()
count = 0
outputs = []
for idx, info in items.items():
feature_str = ""
try:
for key, item in info.items():
if isinstance(item, dict):
if "Hash" in item:
info[key] = text_normalization(
map_hash_to_text[str(item["Hash"])]
)
feature_str += info[key]
else:
# there may be nested dict
for subkey, subitem in item.items():
if isinstance(subitem, dict) and "Hash" in subitem:
item[subkey] = text_normalization(
map_hash_to_text[str(subitem["Hash"])]
)
feature_str += item[subkey]
if feature_str in unique_set:
continue
unique_set.add(feature_str)
outputs.append(info)
count += 1
if 0 < max_count <= count:
return
except KeyError:
print("warning: ", idx, "text hash not found")
if output_path:
with open(output_path, "w", encoding="utf-8") as f:
for info in outputs:
print(json.dumps(info, ensure_ascii=False), file=f)
return outputs
def get_avatar(repo: str, map_hash_to_text: dict, output_path: str, max_count=-1):
repo = os.path.join(repo, "ExcelOutput")
with open(os.path.join(repo, "VoiceAtlas.json"), "r", encoding="utf-8") as f:
map_avatar_to_voiceline = {}
for avatar_id, info in json.load(f).items():
if avatar_id not in map_avatar_to_voiceline:
map_avatar_to_voiceline[avatar_id] = []
for sub_info in info.values():
voice_line = {
"title": text_normalization(
map_hash_to_text[str(sub_info["VoiceTitle"]["Hash"])]
),
"Voice_M": text_normalization(
map_hash_to_text[str(sub_info["Voice_M"]["Hash"])]
),
"Voice_F": text_normalization(
map_hash_to_text[str(sub_info["Voice_F"]["Hash"])]
),
"UnlockDesc": text_normalization(
map_hash_to_text[str(sub_info["UnlockDesc"]["Hash"])]
),
}
for key in list(voice_line.keys()):
if "N/A" in voice_line[key]:
del voice_line[key]
map_avatar_to_voiceline[avatar_id].append(voice_line)
with open(os.path.join(repo, "StoryAtlas.json"), "r", encoding="utf-8") as f:
map_avatar_to_story = {}
for avatar_id, info in json.load(f).items():
if avatar_id not in map_avatar_to_story:
map_avatar_to_story[avatar_id] = {}
for story_id, sub_info in info.items():
map_avatar_to_story[avatar_id][story_id] = text_normalization(
map_hash_to_text[str(sub_info["Story"]["Hash"])]
)
with open(os.path.join(repo, "AvatarCamp.json"), "r", encoding="utf-8") as f:
map_camp_to_name = json.load(f)
for camp_id, info in map_camp_to_name.items():
map_camp_to_name[camp_id] = text_normalization(
map_hash_to_text[str(info["Name"]["Hash"])]
)
with open(os.path.join(repo, "AvatarAtlas.json"), "r", encoding="utf-8") as f:
map_avatar_to_atlas = json.load(f)
for avatar_id, info in map_avatar_to_atlas.items():
map_avatar_to_atlas[avatar_id] = {
"camp": map_camp_to_name[str(info["CampID"])],
"CV_CN": map_hash_to_text[str(info["CV_CN"]["Hash"])],
"CV_JP": map_hash_to_text[str(info["CV_JP"]["Hash"])],
"CV_KR": map_hash_to_text[str(info["CV_KR"]["Hash"])],
"CV_EN": map_hash_to_text[str(info["CV_EN"]["Hash"])],
}
with open(os.path.join(repo, "AvatarSkillConfig.json"), "r", encoding="utf-8") as f:
map_skill_to_info = json.load(f)
for skill_id, info in map_skill_to_info.items():
level_info_list = []
for level_id, sub_info in info.items():
param_list = [p["Value"] for p in sub_info["ParamList"]]
simple_param_list = [p["Value"] for p in sub_info["SimpleParamList"]]
level_info = {
level_id: {
key: text_normalization(
map_hash_to_text.get(str(sub_info[key]["Hash"]), "N/A")
)
for key in [
"SkillDesc",
"SimpleSkillDesc",
]
}
}
for i, (param, simple_param) in enumerate(
zip(param_list, simple_param_list)
):
if isinstance(param, float):
param = f"{100 * param:0.0f}"
simple_param = f"{100 * simple_param:0.0f}"
else:
param = f"{param}"
simple_param = f"{simple_param}"
level_info[level_id]["SkillDesc"] = re.sub(
f"#{i+1}\[[^]]+]", param, level_info[level_id]["SkillDesc"]
)
level_info[level_id]["SimpleSkillDesc"] = re.sub(
f"#{i+1}\[[^]]+]",
simple_param,
level_info[level_id]["SimpleSkillDesc"],
)
assert "#" not in level_info[level_id]["SkillDesc"]
level_info_list.append(level_info)
map_skill_to_info[skill_id] = {
"SkillName": map_hash_to_text.get(str(sub_info["SkillName"]["Hash"])),
"SkillTag": map_hash_to_text.get(str(sub_info["SkillTag"]["Hash"])),
"SkillTypeDesc": map_hash_to_text.get(
str(sub_info["SkillTypeDesc"]["Hash"])
),
"levels": level_info_list,
}
with open(os.path.join(repo, "AvatarConfig.json"), "r", encoding="utf-8") as f:
basic_info = json.load(f)
map_avatar_to_info = {}
for avatar_id, info in basic_info.items():
if avatar_id not in map_avatar_to_story:
continue
map_avatar_to_info[avatar_id] = {
# todo: AvatarCutinIntroText, AvatarDesc, AvatarFullName is none
"basic": {
"Name": text_normalization(
map_hash_to_text[str(info["AvatarName"]["Hash"])]
),
"Camp": map_avatar_to_atlas[avatar_id]["camp"],
"AvatarVOTag": info["AvatarVOTag"],
"DamageType": info["DamageType"],
"AvatarBaseType": info["AvatarBaseType"],
"CV": {
k: v
for k, v in map_avatar_to_atlas[avatar_id].items()
if "CV" in k
},
},
"dialogue_lines": map_avatar_to_voiceline[avatar_id],
"story": map_avatar_to_story[avatar_id],
"skill": [map_skill_to_info[str(s)] for s in info["SkillList"]],
}
count = 0
with open(output_path, "w", encoding="utf-8") as f:
# json.dump(map_avatar_to_info, f, ensure_ascii=False, indent=4)
for i, (_, info) in enumerate(map_avatar_to_info.items()):
avatar_name = info["basic"]["Name"]
print(json.dumps({avatar_name: info}, ensure_ascii=False), file=f)
count += 1
if 0 < max_count <= count:
break
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--repo",
default="../StarRailData",
type=str,
required=True,
help="data dir",
)
parser.add_argument("--lang", default="CHS", type=str, help="language type")
parser.add_argument("--max_count", default=-1, type=str, help="max_count")
args = parser.parse_args()
output_dir = "data"
output_dir = os.path.join(output_dir, "misc", args.lang)
os.makedirs(output_dir, exist_ok=True)
map_hash_to_text = load_text_hash_map(args.repo, args.lang)
map_hash_to_text["371857150"] = "N/A"
# simple tasks
for input_name, output_name in [
("BookSeriesConfig.json", "books.jsonl"),
("ItemConfig.json", "items.jsonl"),
("MazeBuff.json", "maze_buff.jsonl"),
]:
get_misc(
input_path=os.path.join(args.repo, "ExcelOutput", input_name),
output_path=os.path.join(output_dir, output_name),
map_hash_to_text=map_hash_to_text,
max_count=args.max_count,
)
# complex tasks
get_avatar(
args.repo,
map_hash_to_text,
output_path=os.path.join(output_dir, "avatar.jsonl"),
max_count=args.max_count,
)