dead-cells-wiki/data/convert/31-0/melee.py

39 lines
1.1 KiB
Python
Raw Normal View History

2022-09-28 09:39:43 +08:00
#!/usr/bin/env python3
# # -*- coding: utf-8 -*-
import json
import re
with open("../../extraction/raw-31-0/data.cdb.json") as f:
raw = json.load(f)
with open("../../clean/31-0/main.zh.mo.json") as f:
trans = json.load(f)
lines = raw["sheets"][1]["lines"]
melee = []
for i in lines:
if i["group"] == 4:
melee.append(i)
i["name"] = trans[i["name"]]["msgstr"][0]
if "ambiantDesc" in i:
i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0]
if "gameplayDesc" in i:
i["gameplayDesc"] = trans[i["gameplayDesc"].strip()]["msgstr"][0]
if i["props"]:
def replace_props(m):
result = i["props"][m.group(1)]
if isinstance(result, list):
result = result[0]
if not isinstance(result, str):
result = str(result)
return result
i["gameplayDesc"], _ = re.subn(
r"::\+?(.*?)::", replace_props, i["gameplayDesc"]
)
print(json.dumps(melee, ensure_ascii=False))