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

66 lines
2.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
2022-09-29 10:27:01 +08:00
import io
from db import *
from PIL import Image
2022-09-28 09:39:43 +08:00
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)
2022-09-29 10:27:01 +08:00
img = Image.open("../../extraction/raw-31-0/cardIcons.png")
db.bind(provider="sqlite", filename="../../clean/31-0/data.sqlite3")
db.generate_mapping(create_tables=True)
2022-09-28 09:39:43 +08:00
lines = raw["sheets"][1]["lines"]
2022-09-29 10:27:01 +08:00
with db_session:
for i in lines:
if i["group"] == 4:
i["name"] = trans[i["name"]]["msgstr"][0]
if "ambiantDesc" in i:
i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0]
else:
i["ambiantDesc"] = ""
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"]
)
else:
i["gameplayDesc"] = ""
x = i["icon"]["x"] * 24
y = i["icon"]["y"] * 24
box = (x, y, x + 24, y + 24)
region = img.crop(box)
region_arr = io.BytesIO()
region.save(region_arr, format="PNG")
2022-09-29 11:28:58 +08:00
stats_map = {"Brutality": 1, "Survival": 2, "Tactic": 4}
stats = 0
for t in ["tier1", "tier2"]:
if t in i:
stats += stats_map[i[t]]
2022-09-29 10:27:01 +08:00
Melee(
name=i["name"],
description=i["ambiantDesc"],
mechanism=i["gameplayDesc"],
2022-09-29 11:28:58 +08:00
icon=region_arr.getbuffer().tobytes(),
stats=stats,
2022-09-29 10:27:01 +08:00
)