diff --git a/.gitignore b/.gitignore index 1d74e21..16dcb32 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .vscode/ +env/ +__pycache__/ diff --git a/README.md b/README.md index 6e947c4..a90bf10 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,11 @@ - [data](data/README.md):从死亡细胞的数据包里提取数据 - [qqbot](qqbot/README.md):QQ 机器人 + +Python 的虚拟环境: + +```bash +python3 -m venv env +. env/bin/activate +pip install -r requirements.txt +``` diff --git a/data/clean/31-0/data.sqlite3 b/data/clean/31-0/data.sqlite3 new file mode 100644 index 0000000..56bacbf Binary files /dev/null and b/data/clean/31-0/data.sqlite3 differ diff --git a/data/convert/31-0/db.py b/data/convert/31-0/db.py new file mode 100644 index 0000000..f8d801d --- /dev/null +++ b/data/convert/31-0/db.py @@ -0,0 +1,10 @@ +from pony.orm import * + +db = Database() + + +class Melee(db.Entity): + name = Required(str) + description = Optional(str) + mechanism = Optional(str) + icon = Required(bytes) diff --git a/data/convert/31-0/melee.py b/data/convert/31-0/melee.py index ee4cfa7..f3b1661 100755 --- a/data/convert/31-0/melee.py +++ b/data/convert/31-0/melee.py @@ -3,36 +3,57 @@ import json import re +import io +from db import * +from PIL import Image +from playwright.sync_api import sync_playwright 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) +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) 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"]: +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 + 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"] - ) + 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") - -print(json.dumps(melee, ensure_ascii=False)) + Melee( + name=i["name"], + description=i["ambiantDesc"], + mechanism=i["gameplayDesc"], + icon=region_arr.getbuffer().tobytes() + ) diff --git a/data/convert/README.md b/data/convert/README.md index 3b3bc79..7351a1b 100644 --- a/data/convert/README.md +++ b/data/convert/README.md @@ -338,4 +338,4 @@ ``` - `group` 为 15 的是 `BossRushStatueUnlock`,意义不明 -先做近战武器。在 `melee.py` 中提取了所有近战数据。数据的 `name`、`gameplayDesc` 和 `ambiantDesc` 需要翻译。其中 `name` 一定存在,其余两者不一定存在;这两者有可能有多余的空格,所以需要去掉多余的空格;`gameplayDesc` 中有 `::duration::` 格式的部分,对应的值在 `props` 属性中,需要进行替换。 +先做近战武器。在 `melee.py` 中提取了所有近战数据。数据的 `name`、`gameplayDesc` 和 `ambiantDesc` 需要翻译。其中 `name` 一定存在,其余两者不一定存在;这两者有可能有多余的空格,所以需要去掉多余的空格;`gameplayDesc` 中有 `::duration::` 格式的部分,对应的值在 `props` 属性中,需要进行替换。双手武器只有一个的 `droppable` 为 `True`。掘金镐有两份数据,其中只有一份是可掉落的。 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..22e03e2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +black==22.8.0 +bottle==0.12.23 +click==8.1.3 +mypy-extensions==0.4.3 +pathspec==0.10.1 +Pillow==9.2.0 +platformdirs==2.5.2 +pony==0.7.16 +tomli==2.0.1