From 2176fdf803f7cbc7cb504877886466500a61e1d5 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Fri, 10 Jan 2025 02:27:51 +0800 Subject: [PATCH] Fix: Getting index of a digit chapter when looking for a non-digit chapter (#4504) --- campaign/event_20200917_cn/campaign_base.py | 8 ++-- campaign/event_20201029_cn/campaign_base.py | 8 ++-- campaign/event_20201126_cn/campaign_base.py | 2 +- campaign/event_20210121_cn/campaign_base.py | 8 ++-- campaign/event_20210722_cn/campaign_base.py | 8 ++-- campaign/event_20220324_cn/campaign_base.py | 2 +- campaign/event_20220818_cn/campaign_base.py | 2 +- campaign/event_20221124_cn/campaign_base.py | 2 +- campaign/event_20230525_cn/campaign_base.py | 8 ++-- campaign/event_20231026_cn/campaign_base.py | 2 +- campaign/event_20231123_cn/campaign_base.py | 2 +- campaign/event_20240425_cn/campaign_base.py | 2 +- campaign/event_20241024_cn/campaign_base.py | 2 +- campaign/event_20241121_cn/campaign_base.py | 4 +- .../war_archives_20190911_cn/campaign_base.py | 8 ++-- .../war_archives_20200917_cn/campaign_base.py | 8 ++-- module/campaign/campaign_ocr.py | 2 +- module/campaign/campaign_ui.py | 44 ++++++++++++++----- 18 files changed, 72 insertions(+), 50 deletions(-) diff --git a/campaign/event_20200917_cn/campaign_base.py b/campaign/event_20200917_cn/campaign_base.py index fb6371b57..1eee0e485 100644 --- a/campaign/event_20200917_cn/campaign_base.py +++ b/campaign/event_20200917_cn/campaign_base.py @@ -27,7 +27,7 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') @@ -39,11 +39,11 @@ class CampaignBase(CampaignBase_): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': self.campaign_ensure_mode('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': self.ui_goto_sp() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in ['t', 'ts', 'ht', 'hts']: self.ui_goto_event() @@ -60,7 +60,7 @@ class CampaignBase(CampaignBase_): if chapter == 'ex_sp': self.campaign_ensure_mode('ex') # Get stage - self.campaign_ensure_chapter(index=1) + self.campaign_ensure_chapter(1) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/campaign/event_20201029_cn/campaign_base.py b/campaign/event_20201029_cn/campaign_base.py index fb2102c70..845be7574 100644 --- a/campaign/event_20201029_cn/campaign_base.py +++ b/campaign/event_20201029_cn/campaign_base.py @@ -44,10 +44,10 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in 'abcd' or chapter == 'ex_sp': self.ui_goto_event() @@ -57,11 +57,11 @@ class CampaignBase(CampaignBase_): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': pass # Difference - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': self.ui_goto_event() # Difference - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/campaign/event_20201126_cn/campaign_base.py b/campaign/event_20201126_cn/campaign_base.py index 987753757..705ee7f5f 100644 --- a/campaign/event_20201126_cn/campaign_base.py +++ b/campaign/event_20201126_cn/campaign_base.py @@ -54,7 +54,7 @@ class CampaignBase(CampaignBase_): def campaign_set_chapter_event(self, chapter, mode='normal'): self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True def campaign_get_entrance(self, name): diff --git a/campaign/event_20210121_cn/campaign_base.py b/campaign/event_20210121_cn/campaign_base.py index 7bc5fe4f4..51bdc0fe0 100644 --- a/campaign/event_20210121_cn/campaign_base.py +++ b/campaign/event_20210121_cn/campaign_base.py @@ -15,10 +15,10 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_weigh_anchor() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in 'abcd' or chapter == 'ex_sp' or chapter in ['as', 'cs']: self.ui_goto_event() @@ -28,11 +28,11 @@ class CampaignBase(CampaignBase_): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': self.campaign_ensure_mode('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': self.ui_goto_sp() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/campaign/event_20210722_cn/campaign_base.py b/campaign/event_20210722_cn/campaign_base.py index c0400be60..747f97ba8 100644 --- a/campaign/event_20210722_cn/campaign_base.py +++ b/campaign/event_20210722_cn/campaign_base.py @@ -72,10 +72,10 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in ['a', 'b', 'c', 'd', 'ex_sp', 'as', 'bs', 'cs', 'ds']: self.ui_goto_event() @@ -86,12 +86,12 @@ class CampaignBase(CampaignBase_): elif chapter == 'ex_sp': # self.campaign_ensure_mode('ex') pass # Difference - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': # self.ui_goto_sp() self.ui_goto_event() # Difference - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/campaign/event_20220324_cn/campaign_base.py b/campaign/event_20220324_cn/campaign_base.py index 9e82fae4c..178bb8ef3 100644 --- a/campaign/event_20220324_cn/campaign_base.py +++ b/campaign/event_20220324_cn/campaign_base.py @@ -5,7 +5,7 @@ class CampaignBase(CampaignBase_): def campaign_set_chapter_sp(self, chapter, mode='normal'): if chapter == 'sp': self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True else: return False diff --git a/campaign/event_20220818_cn/campaign_base.py b/campaign/event_20220818_cn/campaign_base.py index 9b2408a57..925e18acb 100644 --- a/campaign/event_20220818_cn/campaign_base.py +++ b/campaign/event_20220818_cn/campaign_base.py @@ -8,7 +8,7 @@ class CampaignBase(CampaignBase_): logger.info('Set chapter SP') if chapter in ['sp', 'sp_sp']: self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True else: return False diff --git a/campaign/event_20221124_cn/campaign_base.py b/campaign/event_20221124_cn/campaign_base.py index 29fd7794c..5589ae80c 100644 --- a/campaign/event_20221124_cn/campaign_base.py +++ b/campaign/event_20221124_cn/campaign_base.py @@ -15,7 +15,7 @@ class CampaignBase(CampaignBase_): def campaign_set_chapter_event(self, chapter, mode='normal'): if chapter.startswith('t'): self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True return super().campaign_set_chapter_event(chapter, mode=mode) diff --git a/campaign/event_20230525_cn/campaign_base.py b/campaign/event_20230525_cn/campaign_base.py index c52e464b3..71873058a 100644 --- a/campaign/event_20230525_cn/campaign_base.py +++ b/campaign/event_20230525_cn/campaign_base.py @@ -29,7 +29,7 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') @@ -41,11 +41,11 @@ class CampaignBase(CampaignBase_): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': self.campaign_ensure_mode('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': self.ui_goto_sp() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in ['t', 'ts', 'ht', 'hts']: self.ui_goto_event() @@ -68,7 +68,7 @@ class CampaignBase(CampaignBase_): else: self._campaign_ball_set('red') # Get stage - self.campaign_ensure_chapter(index=1) + self.campaign_ensure_chapter(1) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/campaign/event_20231026_cn/campaign_base.py b/campaign/event_20231026_cn/campaign_base.py index 420866ae7..9e29f6088 100644 --- a/campaign/event_20231026_cn/campaign_base.py +++ b/campaign/event_20231026_cn/campaign_base.py @@ -13,7 +13,7 @@ class CampaignBase(CampaignBase_): def campaign_set_chapter_event(self, chapter, mode='normal'): self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True def _campaign_get_chapter_index(self, name): diff --git a/campaign/event_20231123_cn/campaign_base.py b/campaign/event_20231123_cn/campaign_base.py index 808f9ead5..312a5380a 100644 --- a/campaign/event_20231123_cn/campaign_base.py +++ b/campaign/event_20231123_cn/campaign_base.py @@ -13,7 +13,7 @@ class CampaignBase(CampaignBase_): def campaign_set_chapter_event(self, chapter, mode='normal'): self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True def _campaign_get_chapter_index(self, name): diff --git a/campaign/event_20240425_cn/campaign_base.py b/campaign/event_20240425_cn/campaign_base.py index 9c59c5aa7..00f05b6cc 100644 --- a/campaign/event_20240425_cn/campaign_base.py +++ b/campaign/event_20240425_cn/campaign_base.py @@ -14,7 +14,7 @@ class CampaignBase(CampaignBase_): def campaign_set_chapter_event(self, chapter, mode='normal'): self.ui_goto_event() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True def _campaign_get_chapter_index(self, name): diff --git a/campaign/event_20241024_cn/campaign_base.py b/campaign/event_20241024_cn/campaign_base.py index b67c773ad..7ab2a5b0d 100644 --- a/campaign/event_20241024_cn/campaign_base.py +++ b/campaign/event_20241024_cn/campaign_base.py @@ -42,6 +42,6 @@ class CampaignBase(CampaignBase_): ASIDE_SWITCH_20241219.set('part2', main=self) else: logger.warning(f'Stage {chapter}{stage} is not in event_20241024') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return super().campaign_set_chapter_20241219(chapter, stage, mode) diff --git a/campaign/event_20241121_cn/campaign_base.py b/campaign/event_20241121_cn/campaign_base.py index cbf57f182..b6edbed38 100644 --- a/campaign/event_20241121_cn/campaign_base.py +++ b/campaign/event_20241121_cn/campaign_base.py @@ -26,11 +26,11 @@ class CampaignBase(CampaignBase_): self.ui_goto_event() MODE_SWITCH_20241219.set('combat', main=self) ASIDE_SWITCH_20241219.set('part1', main=self) - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if chapter == 'ttl': self.ui_goto_event() MODE_SWITCH_20241219.set('combat', main=self) ASIDE_SWITCH_20241219.set('part2', main=self) - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return super().campaign_set_chapter_20241219(chapter, stage, mode) diff --git a/campaign/war_archives_20190911_cn/campaign_base.py b/campaign/war_archives_20190911_cn/campaign_base.py index 0007c5839..397ee6e87 100644 --- a/campaign/war_archives_20190911_cn/campaign_base.py +++ b/campaign/war_archives_20190911_cn/campaign_base.py @@ -25,10 +25,10 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in 'abcd' or chapter == 'ex_sp' or chapter in ['as', 'cs']: self.ui_goto_event() @@ -38,11 +38,11 @@ class CampaignBase(CampaignBase_): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': self.campaign_ensure_mode('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': self.ui_goto_sp() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/campaign/war_archives_20200917_cn/campaign_base.py b/campaign/war_archives_20200917_cn/campaign_base.py index 97465d2d8..678fc143e 100644 --- a/campaign/war_archives_20200917_cn/campaign_base.py +++ b/campaign/war_archives_20200917_cn/campaign_base.py @@ -27,7 +27,7 @@ class CampaignBase(CampaignBase_): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') @@ -39,11 +39,11 @@ class CampaignBase(CampaignBase_): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': self.campaign_ensure_mode('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter == 'sp': self.ui_goto_sp() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) elif chapter in ['t', 'ts', 'ht', 'hts']: self.ui_goto_event() @@ -60,7 +60,7 @@ class CampaignBase(CampaignBase_): if chapter == 'ex_sp': self.campaign_ensure_mode('ex') # Get stage - self.campaign_ensure_chapter(index=1) + self.campaign_ensure_chapter(1) else: logger.warning(f'Unknown campaign chapter: {name}') diff --git a/module/campaign/campaign_ocr.py b/module/campaign/campaign_ocr.py index 103787453..9dc04193e 100644 --- a/module/campaign/campaign_ocr.py +++ b/module/campaign/campaign_ocr.py @@ -13,7 +13,7 @@ from module.template.assets import * class CampaignOcr(ModuleBase): stage_entrance = {} - campaign_chapter = 0 + campaign_chapter: str = '0' # An approximate area where stages will appear for faster template matching _stage_detect_area = (87, 117, 1151, 636) diff --git a/module/campaign/campaign_ui.py b/module/campaign/campaign_ui.py index c83373f32..13cbf285b 100644 --- a/module/campaign/campaign_ui.py +++ b/module/campaign/campaign_ui.py @@ -36,16 +36,33 @@ ASIDE_SWITCH_20241219.add_state('sp', CHAPTER_20241219_SP) ASIDE_SWITCH_20241219.add_state('ex', CHAPTER_20241219_EX) +def is_digit_chapter(chapter): + """ + Args: + chapter (int, str): Chapter. Such as 7, 'd', 'sp'. + + Returns: + bool: + """ + if isinstance(chapter, int): + return True + try: + return chapter[0].isdigit() + except IndexError: + return False + + class CampaignUI(MapOperation, CampaignEvent, CampaignOcr): ENTRANCE = Button(area=(), color=(), button=(), name='default_button') - def campaign_ensure_chapter(self, index, skip_first_screenshot=True): + def campaign_ensure_chapter(self, chapter, skip_first_screenshot=True): """ Args: - index (int, str): Chapter. Such as 7, 'd', 'sp'. + chapter (int, str): Chapter. Such as 7, 'd', 'sp'. skip_first_screenshot: """ - index = self._campaign_get_chapter_index(index) + index = self._campaign_get_chapter_index(chapter) + isdigit = is_digit_chapter(chapter) # A copy of use ui_ensure_index. logger.hr("UI ensure index") @@ -61,12 +78,17 @@ class CampaignUI(MapOperation, CampaignEvent, CampaignOcr): continue current = self.get_chapter_index() + current_isdigit = is_digit_chapter(self.campaign_chapter) logger.attr("Index", current) diff = index - current if diff == 0: break + # Getting 3-7 when looking for D3 + if not (isdigit == current_isdigit): + continue + # 14-4 may be OCR as 4-1 due to slow animation, confirm if it is 4-1 if index >= 11 and index % 10 == current: error_confirm.start() @@ -214,13 +236,13 @@ class CampaignUI(MapOperation, CampaignEvent, CampaignOcr): if chapter.isdigit(): self.ui_goto_campaign() self.campaign_ensure_mode('normal') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) if mode == 'hard': self.campaign_ensure_mode('hard') # info_bar shows: Hard mode for this map is not available yet. # There's also a game bug in EN, HM12 shows not available but it's actually available. self.handle_info_bar() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True else: return False @@ -234,7 +256,7 @@ class CampaignUI(MapOperation, CampaignEvent, CampaignOcr): self.campaign_ensure_mode('hard') elif chapter == 'ex_sp': self.campaign_ensure_mode('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True else: return False @@ -242,7 +264,7 @@ class CampaignUI(MapOperation, CampaignEvent, CampaignOcr): def campaign_set_chapter_sp(self, chapter, mode='normal'): if chapter == 'sp': self.ui_goto_sp() - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True else: return False @@ -261,25 +283,25 @@ class CampaignUI(MapOperation, CampaignEvent, CampaignOcr): self.ui_goto_event() self.campaign_ensure_mode_20241219('combat') self.campaign_ensure_aside_20241219('part1') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True if chapter in ['b', 'd', 'ttl']: self.ui_goto_event() self.campaign_ensure_mode_20241219('combat') self.campaign_ensure_aside_20241219('part2') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True if chapter in ['ex_sp']: self.ui_goto_event() self.campaign_ensure_mode_20241219('combat') self.campaign_ensure_aside_20241219('sp') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True if chapter in ['ex_ex']: self.ui_goto_event() self.campaign_ensure_mode_20241219('combat') self.campaign_ensure_aside_20241219('ex') - self.campaign_ensure_chapter(index=chapter) + self.campaign_ensure_chapter(chapter) return True else: return False