refactor: unify build scripts to Python 3

This commit is contained in:
FlipWind
2026-08-09 00:53:55 +08:00
parent 7c76365942
commit 9b171ed169
13 changed files with 173 additions and 466 deletions
+8 -8
View File
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
"""SFCraft 文档 · 物品贴图自动同步 (Linux / macOS / Unix 版)
"""SFCraft 文档 · 物品贴图自动同步 (Python 3)
与 scripts/sync-items.ps1 逻辑一致:
1. 下载 sfcraft 仓库 textures/item 全部贴图到 assets/items
2. 扫描 content 中 crafting 组件用到的物品 id (支持九格直填与 pattern 别名两种写法)
3. 本地缺失的 id 从 Minecraft wiki 自动获取(自动挑选最新版本渲染)
@@ -50,18 +49,19 @@ ALIASES = {
}
def http_get_json(url, retries=2):
last = None
def http_get_json(url: str, retries: int = 2) -> dict:
for i in range(retries + 1):
try:
req = urllib.request.Request(url, headers={"User-Agent": UA})
with urllib.request.urlopen(req, timeout=30) as resp:
return json.load(resp)
except Exception as e: # noqa: BLE001
last = e
except Exception: # noqa: BLE001
if i < retries:
time.sleep(0.8)
raise last
else:
raise
# 理论上不可达(retries 为负时 range 为空才可能走到), 兜底避免隐式返回 None
raise RuntimeError(f"请求失败(无可用异常信息): {url}")
def http_download(url, target):
@@ -84,7 +84,7 @@ def add_item_id(ids, raw):
def scan_item_ids():
"""扫描 content 下所有 crafting 组件, 收集物品 id。"""
ids = set()
ids: set[str] = set()
for path in sorted(CONTENT_DIR.rglob("*.md")):
try:
text = path.read_text(encoding="utf-8")