mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-22 08:37:42 +00:00
0f33ba733e
* Update data_update.py for removing whitespace in credit ocr result sometimes ocr provides a str like '1 2261000' and conversion to int int('1 2261000') fails. we do a post process here, removing the whitespace and allow the conversion to be successful * Update data_update.py for removing whitespace in credit ocr result sometimes ocr provides a str like '1 2261000' and conversion to int int('1 2261000') fails. we do a post process here, removing the whitespace and allow the conversion to be successful edited to align with standards of this repo
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import re
|
|
|
|
from module.base.timer import Timer
|
|
from module.logger import logger
|
|
from module.ocr.ocr import Digit
|
|
from tasks.base.page import page_item
|
|
from tasks.base.ui import UI
|
|
from tasks.item.assets.assets_item_data import OCR_DATA
|
|
|
|
|
|
class DataUpdate(UI):
|
|
def _get_data(self):
|
|
"""
|
|
Page:
|
|
in: page_item
|
|
"""
|
|
ocr = Digit(OCR_DATA)
|
|
|
|
timeout = Timer(2, count=6).start()
|
|
credit, jade = 0, 0
|
|
while 1:
|
|
data = ocr.detect_and_ocr(self.device.image)
|
|
if len(data) == 2:
|
|
credit, jade = [int(re.sub(r'\s', '', d.ocr_text)) for d in data]
|
|
if credit > 0 or jade > 0:
|
|
break
|
|
|
|
logger.warning(f'Invalid credit and stellar jade: {data}')
|
|
if timeout.reached():
|
|
logger.warning('Get data timeout')
|
|
break
|
|
|
|
logger.attr('Credit', credit)
|
|
logger.attr('StellarJade', jade)
|
|
with self.config.multi_set():
|
|
self.config.stored.Credit.value = credit
|
|
self.config.stored.StallerJade.value = jade
|
|
|
|
return credit, jade
|
|
|
|
def run(self):
|
|
self.ui_ensure(page_item, acquire_lang_checked=False)
|
|
|
|
with self.config.multi_set():
|
|
self._get_data()
|
|
self.config.task_delay(server_update=True)
|