mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-16 06:25:24 +00:00
Add: Detect trailblazers
This commit is contained in:
parent
e3c65ffa46
commit
725c78212e
BIN
assets/share/character/switch/TRAILBLAZER_SEARCH.png
Normal file
BIN
assets/share/character/switch/TRAILBLAZER_SEARCH.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 45 KiB |
BIN
assets/share/character/switch/TrailblazerDestructionFemale.png
Normal file
BIN
assets/share/character/switch/TrailblazerDestructionFemale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/share/character/switch/TrailblazerDestructionMale.png
Normal file
BIN
assets/share/character/switch/TrailblazerDestructionMale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/share/character/switch/TrailblazerPreservationFemale.png
Normal file
BIN
assets/share/character/switch/TrailblazerPreservationFemale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/share/character/switch/TrailblazerPreservationMale.png
Normal file
BIN
assets/share/character/switch/TrailblazerPreservationMale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
@ -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),
|
||||
),
|
||||
)
|
||||
|
@ -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__()
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user