Skip to content

Commit 76671e7

Browse files
committed
refactor: map_loader/UI 跟进 SyncResult + 移除 sibling repo 回退
map_loader: - 之前 _map_dirs() 同时把 data/map 和 ../MaaAssistantArknights/resource/Arknights-Tile-Pos 列进搜索路径,作为开发期 sibling repo fallback。 - 但 syncer 已统一改为只走 GitHub 远程同步到 data/map,map_loader 仍回退 sibling repo 不一致: - 普通用户机器该路径不存在 → 多一次无意义的 stat - 开发机器存在 → 可能跳出 syncer 同步过的版本,混搭旧文件 - 改为单一来源 data/map;docstring 同步更新。 settings_page: - _ResourceWorker.run 之前调 sync_all() / update_all() 后无视返回,一律 emit("资源同步完成") —— 现在拿 SyncResult 列表如实构造 summary,部分失败时把失败步骤名称也带进消息。 - update_all 路径同样跟进,组装资源 SyncResult 摘要。
1 parent f24ce84 commit 76671e7

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

aao/core/geometry/map_loader.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""关卡地图数据加载。
22
3-
数据来源:MaaAssistantArknights/resource/Arknights-Tile-Pos/*.json
3+
数据来源:data/map/*.json(由 aao.resources.syncer 从 MaaAssistantArknights GitHub 同步)。
44
文件名格式:{code}-{type}-level_{stageId}.json,如 main_01-07-obt-main-level_main_01-07.json
55
66
用户输入的代号(如 "1-7")通过 level_codes.json 映射到实际文件名。
@@ -15,14 +15,9 @@
1515
from aao.utils.runtime_paths import project_root
1616

1717

18-
def _map_dirs() -> list[Path]:
19-
"""地图数据搜索路径(优先 data/map,回退 ../MaaAssistantArknights)。"""
20-
root = project_root()
21-
dirs = [
22-
root / "data" / "map",
23-
Path("../MaaAssistantArknights/resource/Arknights-Tile-Pos"),
24-
]
25-
return [d for d in dirs if d.exists()]
18+
def _map_dir() -> Path:
19+
"""地图数据目录。单一来源:syncer 同步到的 data/map。"""
20+
return project_root() / "data" / "map"
2621

2722

2823
def _level_codes() -> dict[str, str]:
@@ -38,20 +33,21 @@ def find_map_file(code: str) -> Path | None:
3833
3934
优先用 level_codes.json 映射;回退到 glob 精确匹配。
4035
"""
36+
d = _map_dir()
37+
if not d.exists():
38+
return None
39+
4140
# 1. 通过 level_codes 映射
4241
codes = _level_codes()
4342
if code in codes:
44-
filename = codes[code]
45-
for d in _map_dirs():
46-
p = d / filename
47-
if p.exists():
48-
return p
43+
p = d / codes[code]
44+
if p.exists():
45+
return p
4946

5047
# 2. glob 精确前缀匹配(如 code 本身就是文件名前缀 main_01-07)
51-
for d in _map_dirs():
52-
for p in d.glob(f"{code}-*.json"):
53-
if "#f#" not in p.name:
54-
return p
48+
for p in d.glob(f"{code}-*.json"):
49+
if "#f#" not in p.name:
50+
return p
5551

5652
return None
5753

aao/ui/settings_page.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,14 @@ def run(self) -> None:
7676
try:
7777
if self._mode == "sync":
7878
self.log.emit("开始同步资源(干员名 + 地图)...")
79-
sync_all()
80-
self.finished_ok.emit("资源同步完成")
79+
results = sync_all()
80+
summary = ";".join(r.message for r in results)
81+
if all(r.ok for r in results):
82+
self.finished_ok.emit(f"资源同步完成({summary})")
83+
else:
84+
# 部分失败也走 finished_ok——结果消息里已包含失败信息,
85+
# 这里不弹 failed 信号以免 UI 显示成" fatal exception"。
86+
self.finished_ok.emit(summary)
8187
elif self._mode == "check_update":
8288
self.log.emit("检查 GitHub 最新版本...")
8389
has, ver, url = UpdateChecker().check_software()
@@ -86,8 +92,12 @@ def run(self) -> None:
8692
else:
8793
self.finished_ok.emit(f"已是最新版本 (v{__version__})")
8894
elif self._mode == "update_all":
89-
UpdateChecker().update_all(progress_cb=lambda m: self.log.emit(m))
90-
self.finished_ok.emit("软件检查 + 资源更新完成")
95+
result = UpdateChecker().update_all(progress_cb=lambda m: self.log.emit(m))
96+
res_summary = ";".join(r.message for r in result["resources"])
97+
if all(r.ok for r in result["resources"]):
98+
self.finished_ok.emit(f"软件检查 + 资源更新完成({res_summary})")
99+
else:
100+
self.finished_ok.emit(res_summary)
91101
except Exception as e: # noqa: BLE001
92102
logger.exception("资源/更新操作失败")
93103
self.failed.emit(str(e))

0 commit comments

Comments
 (0)