diff --git a/module/base/base.py b/module/base/base.py index a5c7b239c..ba2e5b7d5 100644 --- a/module/base/base.py +++ b/module/base/base.py @@ -1,7 +1,9 @@ +import module.config.server as server_ from module.base.button import Button, ButtonWrapper, ClickButton, match_template from module.base.timer import Timer from module.base.utils import * from module.config.config import AzurLaneConfig +from module.config.server import set_server, to_package from module.device.device import Device from module.logger import logger @@ -258,3 +260,23 @@ class ModuleBase: value = load_image(value) self.device.image = value + + def set_server(self, server): + """ + For development. + Change server and affect globally, + including assets and server specific methods. + """ + package = to_package(server) + self.device.package = package + set_server(server) + logger.attr('Server', self.config.SERVER) + + def set_lang(self, lang): + """ + For development. + Change lang and affect globally, + including assets and server specific methods. + """ + server_.server = lang + logger.attr('Language', self.config.SERVER) diff --git a/module/ocr/ocr.py b/module/ocr/ocr.py index 918e2798a..d8e669bdd 100644 --- a/module/ocr/ocr.py +++ b/module/ocr/ocr.py @@ -52,7 +52,8 @@ class OcrResultButton: self.text = boxed_result.ocr_text self.score = boxed_result.score - def match_keyword(self, ocr_text, keyword_classes): + @staticmethod + def match_keyword(ocr_text, keyword_classes): """ Args: ocr_text (str): @@ -95,7 +96,7 @@ class Ocr: def __init__(self, button: ButtonWrapper, lang=None, name=None): self.button: ButtonWrapper = button - self.lang: str = lang if lang is not None else Ocr.server2lang() + self._lang = lang self.name: str = name if name is not None else button.name @classmethod @@ -108,6 +109,10 @@ class Ocr: case _: return 'ch' + @cached_property + def lang(self) -> str: + return self._lang if self._lang is not None else Ocr.server2lang() + @cached_property def model(self) -> TextSystem: return OCR_MODEL.__getattribute__(self.lang) @@ -298,7 +303,8 @@ class Duration(Ocr): seconds = self._sanitize_number(matched.group('seconds')) return timedelta(hours=hours, minutes=minutes, seconds=seconds) - def _sanitize_number(self, number) -> int: + @staticmethod + def _sanitize_number(number) -> int: if number is None: return 0 return int(number)