mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-25 10:01:10 +00:00
Fix: Detect Huohuo by avatar (#289)
This commit is contained in:
parent
a64ce168be
commit
5fb3182b24
BIN
assets/share/character/switch/Huohuo.png
Normal file
BIN
assets/share/character/switch/Huohuo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
@ -3,6 +3,16 @@ from module.base.button import Button, ButtonWrapper
|
|||||||
# This file was auto-generated, do not modify it manually. To generate:
|
# This file was auto-generated, do not modify it manually. To generate:
|
||||||
# ``` python -m dev_tools.button_extract ```
|
# ``` python -m dev_tools.button_extract ```
|
||||||
|
|
||||||
|
Huohuo = ButtonWrapper(
|
||||||
|
name='Huohuo',
|
||||||
|
share=Button(
|
||||||
|
file='./assets/share/character/switch/Huohuo.png',
|
||||||
|
area=(1171, 162, 1189, 180),
|
||||||
|
search=(1151, 142, 1209, 200),
|
||||||
|
color=(187, 181, 173),
|
||||||
|
button=(1171, 162, 1189, 180),
|
||||||
|
),
|
||||||
|
)
|
||||||
OCR_MAP_CHARACTERS = ButtonWrapper(
|
OCR_MAP_CHARACTERS = ButtonWrapper(
|
||||||
name='OCR_MAP_CHARACTERS',
|
name='OCR_MAP_CHARACTERS',
|
||||||
share=Button(
|
share=Button(
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import typing as t
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -52,13 +53,18 @@ class CharacterSwitch(UI):
|
|||||||
logger.warning('Character update timeout')
|
logger.warning('Character update timeout')
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Ocr names
|
||||||
ocr = OcrCharacterName(OCR_MAP_CHARACTERS)
|
ocr = OcrCharacterName(OCR_MAP_CHARACTERS)
|
||||||
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():
|
# Add avatars
|
||||||
buttons.append(trailblazer)
|
characters = [button.matched_keyword for button in buttons]
|
||||||
|
for trailblazer in self._iter_character_by_avatar():
|
||||||
|
if trailblazer.matched_keyword not in characters:
|
||||||
|
buttons.append(trailblazer)
|
||||||
|
|
||||||
|
# Set properties
|
||||||
buttons = sorted(buttons, key=lambda b: area_center(b.area)[1])
|
buttons = sorted(buttons, key=lambda b: area_center(b.area)[1])
|
||||||
self.character_buttons = buttons
|
self.character_buttons = buttons
|
||||||
|
|
||||||
self.characters = [button.matched_keyword for button in self.character_buttons]
|
self.characters = [button.matched_keyword for button in self.character_buttons]
|
||||||
logger.attr('Characters', self.characters)
|
logger.attr('Characters', self.characters)
|
||||||
self.character_current = self._convert_selected_to_character(self._update_current_character())
|
self.character_current = self._convert_selected_to_character(self._update_current_character())
|
||||||
@ -75,7 +81,10 @@ class CharacterSwitch(UI):
|
|||||||
|
|
||||||
return self.characters
|
return self.characters
|
||||||
|
|
||||||
def _get_character_trailblazer(self) -> OcrResultButton | None:
|
def _iter_character_by_avatar(self) -> t.Iterable[OcrResultButton]:
|
||||||
|
"""
|
||||||
|
Detect characters that can't be found by OCR
|
||||||
|
"""
|
||||||
dict_template = {
|
dict_template = {
|
||||||
KEYWORD_CHARACTER_LIST.TrailblazerDestruction: [
|
KEYWORD_CHARACTER_LIST.TrailblazerDestruction: [
|
||||||
TrailblazerDestructionMale,
|
TrailblazerDestructionMale,
|
||||||
@ -86,17 +95,19 @@ class CharacterSwitch(UI):
|
|||||||
TrailblazerPreservationFemale,
|
TrailblazerPreservationFemale,
|
||||||
|
|
||||||
],
|
],
|
||||||
|
KEYWORD_CHARACTER_LIST.Huohuo: [
|
||||||
|
Huohuo,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
for character, templates in dict_template.items():
|
for character, templates in dict_template.items():
|
||||||
for template in templates:
|
for template in templates:
|
||||||
template.load_search(TRAILBLAZER_SEARCH.area)
|
template.load_search(TRAILBLAZER_SEARCH.area)
|
||||||
if template.match_template(self.device.image):
|
if template.match_template(self.device.image):
|
||||||
logger.info(f'Found trailblazer: {template}')
|
logger.info(f'Found avatar {template}')
|
||||||
# Create a fake OcrResultButton object
|
# Create a fake OcrResultButton object
|
||||||
box = BoxedResult(box=template.button, text_img=None, ocr_text='', score=1.0)
|
box = BoxedResult(box=template.button, text_img=None, ocr_text='', score=1.0)
|
||||||
button = OcrResultButton(boxed_result=box, matched_keyword=character)
|
button = OcrResultButton(boxed_result=box, matched_keyword=character)
|
||||||
return button
|
yield button
|
||||||
return None
|
|
||||||
|
|
||||||
def _update_current_character(self) -> list[int]:
|
def _update_current_character(self) -> list[int]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user