Fix: _get_stage_name should before handle_get_chapter_additional (#4094)

so loop can be break
This commit is contained in:
LmeSzinc 2024-08-20 01:31:50 +08:00
parent f12ccb87ef
commit c9349b1bba
2 changed files with 12 additions and 7 deletions

View File

@ -331,28 +331,33 @@ class CampaignOcr(ModuleBase):
logger.warning(f'get_chapter_index: WITHDRAW appears')
raise CampaignNameError
def get_chapter_index(self, image):
def get_chapter_index(self, skip_first_screenshot=True):
"""
A tricky method for ui_ensure_index
Args:
image: Screenshot
skip_first_screenshot:
Returns:
int: Chapter index.
"""
timeout = Timer(2, count=4).start()
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if timeout.reached():
raise CampaignNameError
if self.handle_get_chapter_additional():
continue
image = self.device.image
try:
self._get_stage_name(image)
break
except (IndexError, CampaignNameError):
self.device.screenshot()
image = self.device.image
pass
if self.handle_get_chapter_additional():
continue
return self._campaign_get_chapter_index(self.campaign_chapter)

View File

@ -49,7 +49,7 @@ class CampaignUI(MapOperation, CampaignEvent, CampaignOcr):
if self.handle_chapter_additional():
continue
current = self.get_chapter_index(self.device.image)
current = self.get_chapter_index()
logger.attr("Index", current)
diff = index - current