Repository navigation
fix(GameUi): 过图加载时等待可识别页面,不再盲点关闭按钮 #1944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -476,9 +476,12 @@ def _refresh_current_page(self, destination: Page, skip_first_screenshot: bool) | |
| context="goto_page", | ||
| ) | ||
|
|
||
| def _wait_for_destination(self, destination: Page, timeout: float = 4.0) -> bool: | ||
| def _wait_for_destination(self, destination: Page, timeout: float = 15.0) -> bool: | ||
| """等待下一页面稳定出现。 | ||
|
|
||
| 过图加载期间任何已知页面都识别不到,此时继续等而不是直接判失败; | ||
| 只有确认落到了别的已知页才提前返回失败,避免加载慢被误判成跳转失败。 | ||
|
|
||
| Args: | ||
| destination: 目标页面。 | ||
| timeout: 等待超时时间。 | ||
|
|
@@ -488,10 +491,20 @@ def _wait_for_destination(self, destination: Page, timeout: float = 4.0) -> bool | |
| """ | ||
|
|
||
| timer = Timer(timeout).start() | ||
| last_probe = 0.0 | ||
| while not timer.reached(): | ||
| if self.confirm_page(destination, skip_first_screenshot=False): | ||
| self.navigator.current_page = destination | ||
| return True | ||
| now = time.time() | ||
| if now - last_probe >= 3.0: | ||
| last_probe = now | ||
| landed = self._detect_current_page( | ||
| skip_first_screenshot=True, | ||
| categories=self._navigation_detect_categories(destination), | ||
| ) | ||
| if landed is not None and landed.key != destination.key: | ||
| return False | ||
| return False | ||
|
|
||
| def _execute_transition(self, transition: Transition) -> bool: | ||
|
|
@@ -700,6 +713,19 @@ def detect_page_in(self, *targets: str | Page, include_global: bool = True) -> P | |
|
|
||
| return GameUi._detect_pages(self, pages, skip_first_screenshot=True) | ||
|
|
||
| def _wait_for_any_page(self, timeout: float = 15.0) -> bool: | ||
| """未知页(多半是过图加载)时静等可识别页面出现,期间不点任何关闭按钮。""" | ||
|
|
||
| timer = Timer(timeout).start() | ||
| while not timer.reached(): | ||
| page = self._detect_current_page( | ||
| skip_first_screenshot=False, | ||
| categories=self._default_detect_categories(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 中 · 已识别的目标页面被关闭 在恢复等待期间,如果出现的可识别页面不属于全局类别或当前任务类别, 运行未知页面关闭器之前,请搜索所有已注册的页面类别,包括目标类别。 另见 给 AI 智能体的提示在 `tasks/GameUi/navigator.py` 第 723 行:
**已识别的目标页面被关闭**
在恢复等待期间,如果出现的可识别页面不属于全局类别或当前任务类别,`_wait_for_any_page` 只会搜索全局类别和当前任务类别,因此无法发现该页面;随后 `close_unknown_pages` 会在导航重新识别该页面之前,对它运行关闭器。
运行未知页面关闭器之前,请搜索所有已注册的页面类别,包括目标类别。
另见 `tasks/GameUi/navigator.py:724`。Original comment in English🟡 Medium · Recognized destinations get dismissed When a recognizable page appears outside the global and current-task categories during the recovery wait, Search all registered page categories, including the destination category, before running unknown-page closers. Also at Prompt for AI agentsIn `tasks/GameUi/navigator.py` at line 723:
**Recognized destinations get dismissed**
When a recognizable page appears outside the global and current-task categories during the recovery wait, `_wait_for_any_page` searches only the global and current-task categories, so it misses the page and `close_unknown_pages` runs a closer against it before navigation can re-detect it.
Search all registered page categories, including the destination category, before running unknown-page closers.
Also at `tasks/GameUi/navigator.py:724`. |
||
| ) | ||
| if page is not None: | ||
| return True | ||
| return False | ||
|
|
||
| def close_unknown_pages(self, skip_first_screenshot: bool = True) -> bool: | ||
| """尝试关闭未知页面。 | ||
|
|
||
|
|
@@ -712,6 +738,9 @@ def close_unknown_pages(self, skip_first_screenshot: bool = True) -> bool: | |
|
|
||
| self.maybe_screenshot(skip_first_screenshot) | ||
| logger.warning("Try switch to a supported page") | ||
| if self._wait_for_any_page(timeout=15.0): | ||
| # 等待期间出现了可识别页面,无需关闭动作,交给外层重识别。 | ||
| return False | ||
| for action in [*self.navigator.local_unknown_closers, *self.DEFAULT_UNKNOWN_CLOSERS]: | ||
| action_name = self._action_name(action) | ||
| # 若最后3次执行的都是该动作,则跳过该动作尝试其他动作 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 高 · 成功的页面转换受到惩罚
执行转换操作后、目标页面出现前,如果源页面仍可识别,
_wait_for_destination会将源页面视为一次失败的探测并返回False。因此,目标页面还没来得及出现,_execute_transition就会记录一次失败的转换并施加惩罚。如果检测到的页面仍是转换源页面,请继续轮询;只有目标页面等待超时后才判定失败。
给 AI 智能体的提示
Original comment in English
🟠 High · Successful transitions get penalized
When the source page remains recognizable after the transition action but before the destination appears,
_wait_for_destinationtreats the source page as a failed probe and returnsFalse, so_execute_transitionrecords a failed transition and adds a penalty before the destination has time to appear.Keep polling when the detected page is still the transition source, and only fail after the destination wait expires.
Prompt for AI agents