🗃️ Rendered 31-2 data, added shields

This commit is contained in:
zhbaor 2022-09-30 21:25:52 +08:00
parent 00e5928284
commit ac2a8e4d28
20 changed files with 98 additions and 8 deletions

Binary file not shown.

16
data/convert/31-2/db.py Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env python3
# # -*- coding: utf-8 -*-
from pony.orm import * from pony.orm import *
db = Database() db = Database()
@ -9,3 +12,16 @@ class Melee(db.Entity):
mechanism = Optional(str) mechanism = Optional(str)
icon = Required(bytes) icon = Required(bytes)
stats = Required(int) stats = Required(int)
class Shield(db.Entity):
name = Required(str)
description = Optional(str)
mechanism = Optional(str)
icon = Required(bytes)
stats = Required(int)
if __name__ == "__main__":
db.bind(provider="sqlite", filename="../../clean/31-2/data.sqlite3")
db.generate_mapping(create_tables=True)

View file

@ -6,7 +6,6 @@ import re
import io import io
from db import * from db import *
from PIL import Image from PIL import Image
from playwright.sync_api import sync_playwright
with open("../../extraction/raw-31-2/data.cdb.json") as f: with open("../../extraction/raw-31-2/data.cdb.json") as f:
raw = json.load(f) raw = json.load(f)
@ -15,7 +14,7 @@ with open("../../clean/31-2/main.zh.mo.json") as f:
img = Image.open("../../extraction/raw-31-2/cardIcons.png") img = Image.open("../../extraction/raw-31-2/cardIcons.png")
db.bind(provider="sqlite", filename="../../clean/31-2/data.sqlite3") db.bind(provider="sqlite", filename="../../clean/31-2/data.sqlite3")
db.generate_mapping(create_tables=True) db.generate_mapping()
lines = raw["sheets"][1]["lines"] lines = raw["sheets"][1]["lines"]

68
data/convert/31-2/shield.py Executable file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env python3
# # -*- coding: utf-8 -*-
import json
import re
import io
from db import *
from PIL import Image
with open("../../extraction/raw-31-2/data.cdb.json") as f:
raw = json.load(f)
with open("../../clean/31-2/main.zh.mo.json") as f:
trans = json.load(f)
img = Image.open("../../extraction/raw-31-2/cardIcons.png")
db.bind(provider="sqlite", filename="../../clean/31-2/data.sqlite3")
db.generate_mapping()
lines = raw["sheets"][1]["lines"]
with db_session:
for i in lines:
if i["group"] == 6:
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):
prop_name = m.group(1)
if prop_name == "ShockAffectDuration":
prop_name = "duration2" # 雷盾带电手动触发
result = i["props"][prop_name]
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")
stats_map = {"Brutality": 1, "Survival": 2, "Tactic": 4}
stats = 0
for t in ["tier1", "tier2"]:
if t in i:
stats += stats_map[i[t]]
Shield(
name=i["name"],
description=i["ambiantDesc"],
mechanism=i["gameplayDesc"],
icon=region_arr.getbuffer().tobytes(),
stats=stats,
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View file

@ -14,7 +14,7 @@ with sync_playwright() as p:
browser = p.chromium.launch() browser = p.chromium.launch()
page = browser.new_page(device_scale_factor=3) page = browser.new_page(device_scale_factor=3)
with db_session: with db_session:
for m in Melee.select(): for m in [*Melee.select(), *Shield.select()]:
print(f"rendering {m.name}...") print(f"rendering {m.name}...")
page.goto(f"http://localhost:8080/{m.name}") page.goto(f"http://localhost:8080/{m.name}")
page.locator(".container").screenshot(path=f"./output/{m.name}.png") page.locator(".container").screenshot(path=f"./output/{m.name}.png")

View file

@ -18,10 +18,17 @@ db.generate_mapping()
def melee(name): def melee(name):
with db_session: with db_session:
query = select(w for w in Melee if w.name == name) query = select(w for w in Melee if w.name == name)
weapon = query.first() if query.count() > 0:
mechanism, _ = re.subn( weapon = query.first()
r"{(.*?)@(.*?)}", r"<span class='\2'>\1</span>", weapon.mechanism else:
) query = select(w for w in Shield if w.name == name)
weapon = query.first()
if weapon.mechanism:
mechanism, _ = re.subn(
r"{(.*?)@(.*?)}", r"<span class='\2'>\1</span>", weapon.mechanism
)
else:
mechanism = ""
stats_map = { stats_map = {
1: "brutality", 1: "brutality",
2: "survival", 2: "survival",
@ -35,7 +42,7 @@ def melee(name):
"icon": base64.b64encode(weapon.icon), "icon": base64.b64encode(weapon.icon),
"mechanism": mechanism, "mechanism": mechanism,
"description": weapon.description, "description": weapon.description,
"stats": stats_map[weapon.stats] "stats": stats_map[weapon.stats],
} }