Chore: Abstract DigitCounter.is_format_matched()

This commit is contained in:
LmeSzinc 2024-01-01 22:45:22 +08:00
parent 21a8e276b6
commit 0028681cb4
3 changed files with 7 additions and 3 deletions

View File

@ -350,6 +350,10 @@ class DigitCounter(Ocr):
def __init__(self, button: ButtonWrapper, lang='en', name=None): def __init__(self, button: ButtonWrapper, lang='en', name=None):
super().__init__(button, lang=lang, name=name) super().__init__(button, lang=lang, name=name)
@classmethod
def is_format_matched(cls, result) -> bool:
return '/' in result
def format_result(self, result) -> tuple[int, int, int]: def format_result(self, result) -> tuple[int, int, int]:
""" """
Do OCR on a counter, such as `14/15`, and returns 14, 1, 15 Do OCR on a counter, such as `14/15`, and returns 14, 1, 15
@ -360,7 +364,7 @@ class DigitCounter(Ocr):
result = super().after_process(result) result = super().after_process(result)
logger.attr(name=self.name, text=str(result)) logger.attr(name=self.name, text=str(result))
res = re.search(r'(\d+)/(\d+)', result) res = re.search(r'(\d+)\s*/\s*(\d+)', result)
if res: if res:
groups = [int(s) for s in res.groups()] groups = [int(s) for s in res.groups()]
current, total = int(groups[0]), int(groups[1]) current, total = int(groups[0]), int(groups[1])

View File

@ -84,7 +84,7 @@ class DungeonEvent(UI):
ocr = DoubleEventOcr(OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT) ocr = DoubleEventOcr(OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT)
for row in ocr.detect_and_ocr(self.device.image): for row in ocr.detect_and_ocr(self.device.image):
if '/' not in row.ocr_text: if ocr.is_format_matched(row.ocr_text):
continue continue
remain, _, total = ocr.format_result(row.ocr_text) remain, _, total = ocr.format_result(row.ocr_text)
if total in [3, 12]: if total in [3, 12]:

View File

@ -86,7 +86,7 @@ class DungeonState(UI):
continue continue
if row.ocr_text == '+': if row.ocr_text == '+':
continue continue
if '/' not in row.ocr_text: if ocr.is_format_matched(row.ocr_text):
continue continue
data = ocr.format_result(row.ocr_text) data = ocr.format_result(row.ocr_text)
if data[2] == self.config.stored.TrailblazePower.FIXED_TOTAL: if data[2] == self.config.stored.TrailblazePower.FIXED_TOTAL: