diff --git a/assets/share/character/switch/TRAILBLAZER_SEARCH.png b/assets/share/character/switch/TRAILBLAZER_SEARCH.png new file mode 100644 index 000000000..91b776b16 Binary files /dev/null and b/assets/share/character/switch/TRAILBLAZER_SEARCH.png differ diff --git a/assets/share/character/switch/TrailblazerDestructionFemale.png b/assets/share/character/switch/TrailblazerDestructionFemale.png new file mode 100644 index 000000000..5f23c8cde Binary files /dev/null and b/assets/share/character/switch/TrailblazerDestructionFemale.png differ diff --git a/assets/share/character/switch/TrailblazerDestructionMale.png b/assets/share/character/switch/TrailblazerDestructionMale.png new file mode 100644 index 000000000..545eb4966 Binary files /dev/null and b/assets/share/character/switch/TrailblazerDestructionMale.png differ diff --git a/assets/share/character/switch/TrailblazerPreservationFemale.png b/assets/share/character/switch/TrailblazerPreservationFemale.png new file mode 100644 index 000000000..ffb86fcf4 Binary files /dev/null and b/assets/share/character/switch/TrailblazerPreservationFemale.png differ diff --git a/assets/share/character/switch/TrailblazerPreservationMale.png b/assets/share/character/switch/TrailblazerPreservationMale.png new file mode 100644 index 000000000..82da86b8b Binary files /dev/null and b/assets/share/character/switch/TrailblazerPreservationMale.png differ diff --git a/tasks/character/assets/assets_character_switch.py b/tasks/character/assets/assets_character_switch.py index 7a7fbdd99..0ac313f84 100644 --- a/tasks/character/assets/assets_character_switch.py +++ b/tasks/character/assets/assets_character_switch.py @@ -13,3 +13,53 @@ OCR_MAP_CHARACTERS = ButtonWrapper( button=(1041, 142, 1205, 436), ), ) +TRAILBLAZER_SEARCH = ButtonWrapper( + name='TRAILBLAZER_SEARCH', + share=Button( + file='./assets/share/character/switch/TRAILBLAZER_SEARCH.png', + area=(1151, 142, 1205, 436), + search=(1131, 122, 1225, 456), + color=(131, 127, 137), + button=(1151, 142, 1205, 436), + ), +) +TrailblazerDestructionFemale = ButtonWrapper( + name='TrailblazerDestructionFemale', + share=Button( + file='./assets/share/character/switch/TrailblazerDestructionFemale.png', + area=(1170, 233, 1188, 251), + search=(1150, 213, 1208, 271), + color=(198, 180, 170), + button=(1170, 233, 1188, 251), + ), +) +TrailblazerDestructionMale = ButtonWrapper( + name='TrailblazerDestructionMale', + share=Button( + file='./assets/share/character/switch/TrailblazerDestructionMale.png', + area=(1169, 156, 1187, 174), + search=(1149, 136, 1207, 194), + color=(196, 179, 170), + button=(1169, 156, 1187, 174), + ), +) +TrailblazerPreservationFemale = ButtonWrapper( + name='TrailblazerPreservationFemale', + share=Button( + file='./assets/share/character/switch/TrailblazerPreservationFemale.png', + area=(1166, 243, 1184, 261), + search=(1146, 223, 1204, 281), + color=(194, 169, 155), + button=(1166, 243, 1184, 261), + ), +) +TrailblazerPreservationMale = ButtonWrapper( + name='TrailblazerPreservationMale', + share=Button( + file='./assets/share/character/switch/TrailblazerPreservationMale.png', + area=(1171, 394, 1189, 412), + search=(1151, 374, 1209, 432), + color=(191, 166, 153), + button=(1171, 394, 1189, 412), + ), +) diff --git a/tasks/character/keywords/classes.py b/tasks/character/keywords/classes.py index 925e90908..f00b166fa 100644 --- a/tasks/character/keywords/classes.py +++ b/tasks/character/keywords/classes.py @@ -12,3 +12,6 @@ class CharacterList(Keyword): @cached_property def is_trailblazer(self) -> bool: return 'Trailblazer' in self.name + + def __hash__(self) -> int: + return super().__hash__() diff --git a/tasks/character/switch.py b/tasks/character/switch.py index a7b237eb1..0209ef74c 100644 --- a/tasks/character/switch.py +++ b/tasks/character/switch.py @@ -5,10 +5,10 @@ from scipy import signal from module.base.timer import Timer from module.base.utils import area_center, crop, rgb2luma from module.logger import logger -from module.ocr.ocr import OcrResultButton, OcrWhiteLetterOnComplexBackground +from module.ocr.ocr import BoxedResult, OcrResultButton, OcrWhiteLetterOnComplexBackground from tasks.base.ui import UI -from tasks.character.assets.assets_character_switch import OCR_MAP_CHARACTERS -from tasks.character.keywords import CharacterList, DICT_SORTED_RANGES +from tasks.character.assets.assets_character_switch import * +from tasks.character.keywords import CharacterList, DICT_SORTED_RANGES, KEYWORD_CHARACTER_LIST class OcrCharacterName(OcrWhiteLetterOnComplexBackground): @@ -32,14 +32,45 @@ class CharacterSwitch(UI): - self.characters - self.character_current - self.character_buttons + + Pages: + in: page_main """ ocr = OcrCharacterName(OCR_MAP_CHARACTERS) - self.character_buttons = ocr.matched_ocr(self.device.image, keyword_classes=CharacterList) + buttons = ocr.matched_ocr(self.device.image, keyword_classes=CharacterList) + if trailblazer := self._get_character_trailblazer(): + buttons.append(trailblazer) + buttons = sorted(buttons, key=lambda b: area_center(b.area)[1]) + self.character_buttons = buttons + self.characters = [button.matched_keyword for button in self.character_buttons] logger.attr('Characters', self.characters) self.character_current = self._convert_selected_to_character(self._update_current_character()) return self.characters + def _get_character_trailblazer(self) -> OcrResultButton | None: + dict_template = { + KEYWORD_CHARACTER_LIST.TrailblazerDestruction: [ + TrailblazerDestructionMale, + TrailblazerDestructionFemale, + ], + KEYWORD_CHARACTER_LIST.TrailblazerPreservation: [ + TrailblazerPreservationMale, + TrailblazerPreservationFemale, + + ], + } + for character, templates in dict_template.items(): + for template in templates: + template.load_search(TRAILBLAZER_SEARCH.area) + if template.match_template(self.device.image): + logger.info(f'Found trailblazer: {template}') + # Create a fake OcrResultButton object + box = BoxedResult(box=template.button, text_img=None, ocr_text='', score=1.0) + button = OcrResultButton(boxed_result=box, matched_keyword=character) + return button + return None + def _update_current_character(self) -> list[int]: """ Returns: