diff --git a/data/clean/31-2/data.sqlite3 b/data/clean/31-2/data.sqlite3 index cd2c3f9..3732a4d 100644 Binary files a/data/clean/31-2/data.sqlite3 and b/data/clean/31-2/data.sqlite3 differ diff --git a/data/convert/31-2/db.py b/data/convert/31-2/db.py index b262dd3..94ab555 100755 --- a/data/convert/31-2/db.py +++ b/data/convert/31-2/db.py @@ -22,6 +22,14 @@ class Shield(db.Entity): stats = Required(int) +class Ranged(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) diff --git a/data/convert/31-2/ranged.py b/data/convert/31-2/ranged.py new file mode 100755 index 0000000..d27112f --- /dev/null +++ b/data/convert/31-2/ranged.py @@ -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"] == 5: + i["name"] = trans[i["name"].strip()]["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 = "duration" # 雷盾带电手动触发 + 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]] + + Ranged( + name=i["name"], + description=i["ambiantDesc"], + mechanism=i["gameplayDesc"], + icon=region_arr.getbuffer().tobytes(), + stats=stats, + ) diff --git a/data/render/31-2/server.py b/data/render/31-2/server.py index 3744e6d..cf42bd7 100755 --- a/data/render/31-2/server.py +++ b/data/render/31-2/server.py @@ -15,7 +15,7 @@ db.generate_mapping() @route("/") @view("weapon") -def melee(name): +def weapon(name): with db_session: query = select(w for w in Melee if w.name == name) if query.count() > 0: