🗃️ Store melee data into SQLite
This commit is contained in:
parent
8b847e0f9c
commit
c0fc97a578
7 changed files with 73 additions and 23 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
.vscode/
|
.vscode/
|
||||||
|
env/
|
||||||
|
__pycache__/
|
||||||
|
|
|
@ -4,3 +4,11 @@
|
||||||
|
|
||||||
- [data](data/README.md):从死亡细胞的数据包里提取数据
|
- [data](data/README.md):从死亡细胞的数据包里提取数据
|
||||||
- [qqbot](qqbot/README.md):QQ 机器人
|
- [qqbot](qqbot/README.md):QQ 机器人
|
||||||
|
|
||||||
|
Python 的虚拟环境:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m venv env
|
||||||
|
. env/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
BIN
data/clean/31-0/data.sqlite3
Normal file
BIN
data/clean/31-0/data.sqlite3
Normal file
Binary file not shown.
10
data/convert/31-0/db.py
Normal file
10
data/convert/31-0/db.py
Normal file
|
@ -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)
|
|
@ -3,36 +3,57 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
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:
|
with open("../../extraction/raw-31-0/data.cdb.json") as f:
|
||||||
raw = json.load(f)
|
raw = json.load(f)
|
||||||
with open("../../clean/31-0/main.zh.mo.json") as f:
|
with open("../../clean/31-0/main.zh.mo.json") as f:
|
||||||
trans = json.load(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"]
|
lines = raw["sheets"][1]["lines"]
|
||||||
melee = []
|
|
||||||
|
|
||||||
for i in lines:
|
with db_session:
|
||||||
if i["group"] == 4:
|
for i in lines:
|
||||||
melee.append(i)
|
if i["group"] == 4:
|
||||||
i["name"] = trans[i["name"]]["msgstr"][0]
|
i["name"] = trans[i["name"]]["msgstr"][0]
|
||||||
if "ambiantDesc" in i:
|
if "ambiantDesc" in i:
|
||||||
i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0]
|
i["ambiantDesc"] = trans[i["ambiantDesc"].strip()]["msgstr"][0]
|
||||||
if "gameplayDesc" in i:
|
else:
|
||||||
i["gameplayDesc"] = trans[i["gameplayDesc"].strip()]["msgstr"][0]
|
i["ambiantDesc"] = ""
|
||||||
if i["props"]:
|
if "gameplayDesc" in i:
|
||||||
|
i["gameplayDesc"] = trans[i["gameplayDesc"].strip()]["msgstr"][0]
|
||||||
|
if i["props"]:
|
||||||
|
|
||||||
def replace_props(m):
|
def replace_props(m):
|
||||||
result = i["props"][m.group(1)]
|
result = i["props"][m.group(1)]
|
||||||
if isinstance(result, list):
|
if isinstance(result, list):
|
||||||
result = result[0]
|
result = result[0]
|
||||||
if not isinstance(result, str):
|
if not isinstance(result, str):
|
||||||
result = str(result)
|
result = str(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
i["gameplayDesc"], _ = re.subn(
|
i["gameplayDesc"], _ = re.subn(
|
||||||
r"::\+?(.*?)::", replace_props, i["gameplayDesc"]
|
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")
|
||||||
|
|
||||||
|
Melee(
|
||||||
print(json.dumps(melee, ensure_ascii=False))
|
name=i["name"],
|
||||||
|
description=i["ambiantDesc"],
|
||||||
|
mechanism=i["gameplayDesc"],
|
||||||
|
icon=region_arr.getbuffer().tobytes()
|
||||||
|
)
|
||||||
|
|
|
@ -338,4 +338,4 @@
|
||||||
```
|
```
|
||||||
- `group` 为 15 的是 `BossRushStatueUnlock`,意义不明
|
- `group` 为 15 的是 `BossRushStatueUnlock`,意义不明
|
||||||
|
|
||||||
先做近战武器。在 `melee.py` 中提取了所有近战数据。数据的 `name`、`gameplayDesc` 和 `ambiantDesc` 需要翻译。其中 `name` 一定存在,其余两者不一定存在;这两者有可能有多余的空格,所以需要去掉多余的空格;`gameplayDesc` 中有 `::duration::` 格式的部分,对应的值在 `props` 属性中,需要进行替换。
|
先做近战武器。在 `melee.py` 中提取了所有近战数据。数据的 `name`、`gameplayDesc` 和 `ambiantDesc` 需要翻译。其中 `name` 一定存在,其余两者不一定存在;这两者有可能有多余的空格,所以需要去掉多余的空格;`gameplayDesc` 中有 `::duration::` 格式的部分,对应的值在 `props` 属性中,需要进行替换。双手武器只有一个的 `droppable` 为 `True`。掘金镐有两份数据,其中只有一份是可掉落的。
|
||||||
|
|
9
requirements.txt
Normal file
9
requirements.txt
Normal file
|
@ -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
|
Loading…
Reference in a new issue