49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""dump_master.py —— 从游戏 StreamingAssets 的 Sort.xml 提取各分类 id + 名称。"""
|
|
import json
|
|
import os
|
|
import sys
|
|
import xml.etree.ElementTree as ET
|
|
|
|
BASE = r"D:\bs\Package\Sinmai_Data\StreamingAssets\A000"
|
|
OUT = r"<maipulse>\data\master.json"
|
|
|
|
CATS = {
|
|
"ticket": ("ticket", 12),
|
|
"partner": ("partner", 10),
|
|
"title": ("title", 2),
|
|
"icon": ("icon", 3),
|
|
"frame": ("frame", 11),
|
|
"plate": ("plate", 1),
|
|
"music": ("music", 5),
|
|
}
|
|
|
|
result = {}
|
|
for key, (folder, kind) in CATS.items():
|
|
path = os.path.join(BASE, folder, folder.capitalize() + "Sort.xml")
|
|
if not os.path.exists(path):
|
|
cands = [f for f in os.listdir(os.path.join(BASE, folder)) if f.endswith(".xml")]
|
|
if not cands:
|
|
print("skip", key)
|
|
continue
|
|
path = os.path.join(BASE, folder, cands[0])
|
|
tree = ET.parse(path)
|
|
rows = []
|
|
for node in tree.iter("StringID"):
|
|
i = node.findtext("id")
|
|
s = node.findtext("str")
|
|
if i is None:
|
|
continue
|
|
try:
|
|
iid = int(i)
|
|
except ValueError:
|
|
continue
|
|
rows.append({"id": iid, "name": s or ""})
|
|
rows.sort(key=lambda x: x["id"])
|
|
result[key] = {"kind": kind, "count": len(rows), "items": rows}
|
|
print("%-8s kind=%-3s %5d 条 例: %s" % (key, kind, len(rows), rows[0] if rows else "-"))
|
|
|
|
os.makedirs(os.path.dirname(OUT), exist_ok=True)
|
|
with open(OUT, "w", encoding="utf-8") as f:
|
|
json.dump(result, f, ensure_ascii=False)
|
|
print("\n已写出", OUT, os.path.getsize(OUT), "字节") |