Add searchable wiki catalogue and biology material navigation

This commit is contained in:
shen
2026-10-15 00:48:50 -07:00
parent 6472d17306
commit 9d9993b007
21 changed files with 7926 additions and 3 deletions
+31
View File
@@ -0,0 +1,31 @@
# 百科:当前服务器模板目录
AVA2 参考:`uiwiki.py` 的分类/搜索/升级材料与关联跳转;当前实现使用原生 PORT 界面和当前服务器数据,不加载整个 AVA2 root 或改变物品格式。
服务端的 `tools/wiki/export_public_tables.py` 只读导出 `share/conf` 下四个 proto/name 文件与 `player.refine_proto` 的配方列。导出目录放入客户端忽略的 `build/wiki-source/`:
```sh
python3 tools/wiki/build_catalogue.py --source build/wiki-source
python3 tests/wiki/test_catalogue.py
```
输出 `data/wiki/catalogue.txt` 和 `manifest.json`,包含输入哈希与内容版本。名称使用当前服务器名称及已有中文表,不带角色/账号数据。ITEM_NONE 不能一概过滤:AVA2 生物学家任务石使用此类型。目录只表示模板存在,不保证获取途径。
`scripts/build_zh_locale.py` 自动把目录打为 `wiki.eix/epk`,注册在 pack/Index;Android 增量同步摘要包含目录和生成器。源资料更新后需重新生成、打包并同步两份 pack 和 Index;仅安装新 APK 无法更新静态资料。
运行时安装 `mt_features`、`mt_wiki_data`、`mt_wiki`。模块按版本/字段/长度/数值/范围校验后一次加载,仅创建当前页控件。首次点击小地图旁“百科”加载数据;支持中文/ID、分类、分页、范围 ID、升级目标/材料跳转与返回;点击生物学家材料图标打开对应详情。
`mt_features` 为标准库调用及显式 level 导入保留原生 Python 导入语义;原 packed 游戏脚本的其他四参数导入继续原路径,原始 system.py 字节不改。中文搜索通过 `player.FeatureLocaleToUTF8` 使用同一套原生代码页映射,不要求 Python CJK 扩展。
能力声明 `CAPABILITIES` 当前只打开静态目录;尚未实现服务端能力握手、实时查询协议、掉落/宝箱或模型预览。UI 明示缺失项。升级展示为配方基础值,NPC/道具修正后的实际结果以精炼窗口为准。
集成测试(本机完整资源可用时):
```sh
cmake --build build/native --target port_login_flow_test -j8
MT_TEST_WIKI=1 MT_TEST_MOBILE=1 MT_ASSETS_STRICT=1 \
build/native/src/port/port_login_flow_test \
"$PWD/build/zh-locale/Client" "$PWD/build/release/src/host/python27.zip"
```
测试通过真实 Python 2 UI/鼠标命中验证小地图入口、中文输入、升级跳转/返回、生物学家材料入口、640×360 排版、缺失资料提示与退出,并回归原离线登录/背包/商店/战斗流程。触控模式是桌面宿主回归,不能代替 Android 真机验收。
+112
View File
@@ -0,0 +1,112 @@
#!/usr/bin/env python3
"""Build a bounded, versioned wiki catalogue from the current server's public tables.
No account/character/configuration data is read. Output is UTF-8 TSV, never executable Python.
"""
import argparse
import hashlib
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[2]
FILES = ('item_proto.txt', 'item_names.txt', 'mob_proto.txt', 'mob_names.txt', 'refine.tsv')
def rows(path):
for line in path.read_bytes().splitlines():
cols = line.split(b'\t')
if cols and cols[0].split(b'~')[0].isdigit():
yield cols
def names(path, overlay):
result = {}
for cols in rows(path):
if len(cols) > 1:
result[int(cols[0].split(b'~')[0])] = cols[1].decode('gbk', 'replace')
for path in overlay:
for line in path.read_text(encoding='utf-8').splitlines():
c = line.split('\t', 1)
if len(c) == 2 and c[0].isdigit():
result[int(c[0])] = c[1]
return result
def clean(value):
value = str(value)
if any(c in value for c in '\t\r\n\x00') or len(value) > 256:
raise ValueError('invalid catalogue cell')
# Native text renderer recognizes pipe escape sequences; source names are plain text.
return value.replace('|', '/')
def build(source, output, names_dir):
hashes = {name: hashlib.sha256((source / name).read_bytes()).hexdigest() for name in FILES}
item_names = names(source / 'item_names.txt', [names_dir / 'item_names_zh.txt', names_dir / 'item_names_zh_overlay.txt'])
mob_names = names(source / 'mob_names.txt', [names_dir / 'mob_names_zh.txt', names_dir / 'mob_names_zh_overlay.txt'])
records, items, mobs, refines = [], {}, set(), {}
for c in rows(source / 'item_proto.txt'):
if len(c) < 33:
raise ValueError('truncated item row')
extent = list(map(int, c[0].split(b'~')))
start, end = extent[0], extent[-1]
if not 0 < start <= end < 2**32 or end - start > 10000 or start in items:
raise ValueError('invalid/duplicate item range')
kind, subtype = c[2].decode('ascii'), c[3].decode('ascii')
if kind == 'ITEM_ELK':
continue
level = max([int(c[i+1]) for i in (14, 16) if c[i] == b'LEVEL'] + [0])
name = item_names.get(start, '物品 #%d' % start)
# I id range_end name type subtype minimum_level size refined_vnum refine_set
row = ['I', start, end, name, kind, subtype, level, int(c[4]), int(c[11]), int(c[12])]
items[start] = row
records.append(row)
extents = sorted((v[1], v[2]) for v in items.values())
if any(a[1] >= b[0] for a, b in zip(extents, extents[1:])):
raise ValueError('overlapping item ranges')
for c in rows(source / 'mob_proto.txt'):
if len(c) < 27:
raise ValueError('truncated mob row')
if c[3] not in (b'MONSTER', b'STONE'):
continue
vnum = int(c[0])
if vnum in mobs:
raise ValueError('duplicate monster')
mobs.add(vnum)
# M id name type rank level hp damage_min damage_max experience defense
records.append(['M', vnum, mob_names.get(vnum, '怪物 #%d' % vnum), c[3].decode('ascii'),
c[2].decode('ascii')] + [int(c[i]) for i in (5, 20, 18, 19, 25, 26)])
for c in rows(source / 'refine.tsv'):
if len(c) != 13:
raise ValueError('refine table must contain 13 columns')
values = list(map(int, c))
rid, cost, prob = values[:3]
if rid in refines or rid <= 0 or cost < 0 or not 0 <= prob <= 100:
raise ValueError('invalid refine record')
mats = [(values[i], values[i+1]) for i in range(3, 13, 2) if values[i] or values[i+1]]
if any(v <= 0 or n <= 0 for v, n in mats):
raise ValueError('invalid refine ingredient')
refines[rid] = True
records.append(['R', rid, cost, prob, ','.join('%d:%d' % pair for pair in mats)])
if not items or not mobs or not refines or len(records) > 30000:
raise ValueError('empty or oversized catalogue')
payload = ''.join('\t'.join(clean(c) for c in row) + '\n' for row in records).encode('utf-8')
digest = hashlib.sha256(payload).hexdigest()
output.mkdir(parents=True, exist_ok=True)
(output / 'catalogue.txt').write_bytes(('MTWIKI\t1\t' + digest + '\n').encode('ascii') + payload)
report = dict(schema=1, catalogue_sha256=digest, source_sha256=hashes,
items=len(items), monsters=len(mobs), refine_recipes=len(refines),
source='203 public server tables; no player data',
generator_sha256=hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
localization_sha256={name:hashlib.sha256((names_dir/name).read_bytes()).hexdigest() for name in ('item_names_zh.txt','item_names_zh_overlay.txt','mob_names_zh.txt','mob_names_zh_overlay.txt')},
scope='template catalogue; acquisition and runtime rates not yet queried')
(output / 'manifest.json').write_text(json.dumps(report, ensure_ascii=False, indent=2)+'\n', encoding='utf-8')
return report
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--source', type=Path, required=True)
parser.add_argument('--output', type=Path, default=REPO / 'data/wiki')
parser.add_argument('--names-dir', type=Path, default=REPO / 'data/zh_40250')
args = parser.parse_args()
print(json.dumps(build(args.source, args.output, args.names_dir), ensure_ascii=False, indent=2))