parent
322f565a2b
commit
a44038b148
|
@ -33,5 +33,6 @@ from .backend.ocr import (
|
|||
fuzz,
|
||||
regex,
|
||||
contains,
|
||||
equals,
|
||||
)
|
||||
from .ui import user
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import logging
|
||||
import unicodedata
|
||||
from functools import lru_cache
|
||||
from typing import Callable, NamedTuple
|
||||
|
@ -13,6 +14,7 @@ from .util import Rect, grayscaled, res_path
|
|||
from .debug import result as debug_result, debug
|
||||
from .core import HintBox
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_engine_jp = RapidOCR(
|
||||
rec_model_path=res_path('res/models/japan_PP-OCRv3_rec_infer.onnx'),
|
||||
|
@ -68,6 +70,35 @@ def contains(text: str) -> Callable[[str], bool]:
|
|||
f.__name__ = f"contains('{text}')"
|
||||
return f
|
||||
|
||||
@lru_cache(maxsize=1000)
|
||||
def equals(
|
||||
text: str,
|
||||
*,
|
||||
remove_space: bool = False,
|
||||
ignore_case: bool = True,
|
||||
) -> Callable[[str], bool]:
|
||||
"""
|
||||
返回等于指定文本的函数。
|
||||
|
||||
:param text: 要比较的文本。
|
||||
:param remove_space: 是否忽略空格。默认为 False。
|
||||
:param ignore_case: 是否忽略大小写。默认为 True。
|
||||
"""
|
||||
def compare(s: str) -> bool:
|
||||
nonlocal text
|
||||
|
||||
if ignore_case:
|
||||
text = text.lower()
|
||||
s = s.lower()
|
||||
if remove_space:
|
||||
text = text.replace(' ', '').replace(' ', '')
|
||||
s = s.replace(' ', '').replace(' ', '')
|
||||
|
||||
return text == s
|
||||
compare.__repr__ = lambda: f"equals('{text}')"
|
||||
compare.__name__ = f"equals('{text}')"
|
||||
return compare
|
||||
|
||||
def _is_match(text: str, pattern: re.Pattern | str | StringMatchFunction) -> bool:
|
||||
if isinstance(pattern, re.Pattern):
|
||||
return pattern.match(text) is not None
|
||||
|
@ -300,6 +331,7 @@ class Ocr:
|
|||
|
||||
ret: list[OcrResult | None] = []
|
||||
ocr_results = self.ocr(img, rect=rect, pad=pad)
|
||||
logger.debug(f"ocr_results: {ocr_results}")
|
||||
for text in texts:
|
||||
for result in ocr_results:
|
||||
if _is_match(result.text, text):
|
||||
|
|
|
@ -8,7 +8,7 @@ from . import R
|
|||
from .common import conf, PIdol
|
||||
from .actions.loading import wait_loading_end
|
||||
from .actions.in_purodyuusu import hajime_regular
|
||||
from kotonebot import device, image, ocr, task, action, sleep, contains
|
||||
from kotonebot import device, image, ocr, task, action, sleep, equals
|
||||
from .actions.scenes import loading, at_home, goto_home
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -46,6 +46,7 @@ def select_idol(target_titles: list[str] | PIdol):
|
|||
# 前置条件:[res/sprites/jp/produce/produce_preparation1.png]
|
||||
# 结束状态:[res/sprites/jp/produce/produce_preparation1.png]
|
||||
|
||||
logger.info(f"Find and select idol: {target_titles}")
|
||||
# 进入总览
|
||||
device.update_screenshot()
|
||||
device.click(image.expect(R.Produce.ButtonPIdolOverview))
|
||||
|
@ -54,7 +55,7 @@ def select_idol(target_titles: list[str] | PIdol):
|
|||
|
||||
if isinstance(target_titles, PIdol):
|
||||
target_titles = target_titles.value
|
||||
_target_titles = [contains(t) for t in target_titles]
|
||||
_target_titles = [equals(t, remove_space=True) for t in target_titles]
|
||||
device.update_screenshot()
|
||||
# 定位滑动基准
|
||||
results = image.find_all(R.Produce.IconPIdolLevel)
|
||||
|
@ -95,7 +96,7 @@ def select_idol(target_titles: list[str] | PIdol):
|
|||
device.click(image.expect(R.Common.ButtonConfirmNoIcon))
|
||||
return found
|
||||
|
||||
@action('单次培育')
|
||||
@action('执行培育')
|
||||
def do_produce(idol: PIdol | None = None):
|
||||
"""
|
||||
进行培育流程
|
||||
|
|
Loading…
Reference in New Issue