Skip to content

fix: map page recognition with loot badge & add acquisition API#352

Merged
huan-yp merged 2 commits intoOpenWSGR:mainfrom
yltx:fix/map-page-recognition-and-acquisition-api
Mar 6, 2026
Merged

fix: map page recognition with loot badge & add acquisition API#352
huan-yp merged 2 commits intoOpenWSGR:mainfrom
yltx:fix/map-page-recognition-and-acquisition-api

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Mar 6, 2026

修改内容

1. 修复地图页面识别失败 (战利品 徽标遮挡)

问题: 当出征面板出现「战利品▲」徽标时,徽标覆盖了 TAB_PROBES[0] 探测点 (0.1415, 0.0417),导致该点像素颜色从蓝色/暗色变为徽标颜色。is_tabbed_page() 要求 5 个探测点严格满足 1蓝+4暗,因此返回 False,进而 MapPage.is_current_page() 失败,页面识别器遍历所有 13 个注册页面均无匹配。

修复方式: 将第 0 号探测点的 y 坐标从 0.0417 下移至 0.0650,使其落在标签栏蓝色/暗色背景区域内、但位于徽标遮挡范围之下。判定逻辑 blue_count==1 and dark_count==4 保持不变。

2. 新增游戏状态查询 API

为前端实现「战利品满时结束任务」或「捞船达到 500 上限」等任务终止条件,新增两个端点:

  • GET /api/game/acquisition — 导航至出征面板,OCR 识别今日舰船获取 (X/500) 和战利品获取 (X/50)
  • GET /api/game/context — 返回游戏运行时计数器 (dropped_ship_count, dropped_loot_count, quick_repair_used, current_page)

3. 版本号

2.0.4.dev1 -> 2.0.4

修改文件

  • autowsgr/ui/tabbed_page.py — TAB_PROBES[0] y 坐标下移避开徽标
  • autowsgr/server/main.py — 新增 /api/game/acquisition 和 /api/game/context
  • autowsgr/init.py — 版本号 2.0.4

yltx and others added 2 commits March 6, 2026 16:37
feat: add POST /api/expedition/check endpoint (#350)
- Move TAB_PROBES[0] y from 0.0417 to 0.0650 to avoid loot badge overlay
- Add GET /api/game/acquisition - OCR recognition of ship/loot counts
- Add GET /api/game/context - game context runtime counters
- Bump version to 2.0.4
Copilot AI review requested due to automatic review settings March 6, 2026 11:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves UI robustness and expands the HTTP API for querying in-game state, aimed at enabling front-end stop conditions (e.g., loot/ship acquisition limits) while also shipping the changes as version 2.0.4.

Changes:

  • Adjust TAB_PROBES[0] Y coordinate to avoid being occluded by the “战利品▲” badge, preventing false negatives in tabbed-page detection.
  • Add two new FastAPI endpoints: /api/game/acquisition (OCR-based counts) and /api/game/context (runtime counters).
  • Bump package version from 2.0.4.dev1 to 2.0.4.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
autowsgr/ui/tabbed_page.py Moves a tab probe point downward and documents the “战利品▲” occlusion workaround.
autowsgr/server/main.py Adds new game state query endpoints for acquisition OCR and context counters.
autowsgr/init.py Updates the published package version to 2.0.4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread autowsgr/server/main.py
Comment on lines +495 to +505
from autowsgr.ui.map.page import MapPage

def _recognize() -> dict[str, int | None]:
map_page = MapPage(ctx)
counts = map_page.get_acquisition_counts()
return {
'ship_count': counts.ship_count,
'ship_max': counts.ship_max,
'loot_count': counts.loot_count,
'loot_max': counts.loot_max,
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/api/game/acquisition 的实现里只调用了 MapPage(ctx).get_acquisition_counts(),但没有先通过 ops 层导航到地图页面/出征面板;如果调用该接口时当前不在地图页,ensure_panel() 会在错误页面点击坐标导致识别/导航失败。建议在 _recognize() 里先调用 goto_page(ctx, PageName.MAP)(或提供专门的导航/校验逻辑),再执行面板切换与 OCR。

Copilot uses AI. Check for mistakes.
Comment thread autowsgr/server/main.py
Comment on lines +517 to +532
"""返回当前游戏上下文中的运行时计数器和状态。

不需要截图或画面操作,直接读取内存中的计数器。
"""
try:
ctx = get_context()
except RuntimeError as e:
raise HTTPException(status_code=503, detail=str(e)) from e

return ApiResponse(
success=True,
data={
'dropped_ship_count': ctx.dropped_ship_count,
'dropped_loot_count': ctx.dropped_loot_count,
'quick_repair_used': ctx.quick_repair_used,
'current_page': ctx.current_page,
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/api/game/context 返回的 dropped_ship_count / dropped_loot_count / quick_repair_used / current_page 目前在代码库中没有发现任何地方会更新这些 GameContext 字段(搜索结果只出现在字段定义与本接口)。这会导致接口长期返回默认值(0/None),与“运行时计数器/当前页面”的语义不符。建议要么在产生掉落/消耗快修/导航时实际维护这些字段,要么在接口中改为调用现有的识别函数实时计算(即使需要截图),或移除/重命名这些字段以避免误导。

Suggested change
"""返回当前游戏上下文中的运行时计数器和状态
不需要截图或画面操作直接读取内存中的计数器
"""
try:
ctx = get_context()
except RuntimeError as e:
raise HTTPException(status_code=503, detail=str(e)) from e
return ApiResponse(
success=True,
data={
'dropped_ship_count': ctx.dropped_ship_count,
'dropped_loot_count': ctx.dropped_loot_count,
'quick_repair_used': ctx.quick_repair_used,
'current_page': ctx.current_page,
"""返回当前游戏上下文中的计数器占位信息
注意当前实现未维护掉落/快修/页面等运行时计数器这些字段仅作为占位符返回 None
"""
try:
ctx = get_context()
except RuntimeError as e:
raise HTTPException(status_code=503, detail=str(e)) from e
# 目前 GameContext 未维护以下计数器,避免返回误导性的默认值 (0/None),统一返回 None 占位。
return ApiResponse(
success=True,
data={
'dropped_ship_count': None,
'dropped_loot_count': None,
'quick_repair_used': None,
'current_page': None,

Copilot uses AI. Check for mistakes.
@huan-yp huan-yp merged commit de5800a into OpenWSGR:main Mar 6, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants