Merge pull request #673 from LmeSzinc/dev

Bug fix
This commit is contained in:
LmeSzinc 2024-11-13 10:48:31 +08:00 committed by GitHub
commit 649f11b363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 70 additions and 62 deletions

View File

@ -9,16 +9,16 @@ adbutils==1.2.9
uiautomator2==2.16.17
uiautomator2cache==0.3.1
wrapt>=1.14.0
lz4
lz4==4.3.2
av==10.0.0
psutil==5.9.3
# Utils
rich
tqdm
jellyfish
pyyaml
inflection
rich==13.3.5
tqdm==4.65.0
jellyfish==0.11.2
pyyaml==6.0
inflection==0.5.1
prettytable==2.2.1
pydantic>=2.4
onepush==1.3.0
@ -37,4 +37,4 @@ srcmap==2.3.20240701
# For dev
# pip-tools
pynput
pynput==1.7.6

View File

@ -1,7 +1,7 @@
from module.base.button import ButtonWrapper
from module.base.decorator import run_once
from module.base.timer import Timer
from module.exception import GameNotRunningError, GamePageUnknownError
from module.exception import GameNotRunningError, GamePageUnknownError, HandledError
from module.logger import logger
from module.ocr.ocr import Ocr
from tasks.base.assets.assets_base_main_page import ROGUE_LEAVE_FOR_NOW, ROGUE_LEAVE_FOR_NOW_OE
@ -98,9 +98,7 @@ class UI(MainPage):
if self.handle_popup_confirm():
timeout.reset()
continue
if self.is_in_login_confirm(interval=5):
self.device.click(LOGIN_CONFIRM)
timeout.reset()
if self.handle_login_confirm():
continue
if self.appear(MAP_LOADING, interval=5):
logger.info('Map loading')
@ -172,8 +170,7 @@ class UI(MainPage):
continue
if self.handle_popup_confirm():
continue
if self.is_in_login_confirm(interval=5):
self.device.click(LOGIN_CONFIRM)
if self.handle_login_confirm():
continue
# Reset connection
@ -363,6 +360,17 @@ class UI(MainPage):
return appear
def handle_login_confirm(self):
"""
If LOGIN_CONFIRM appears, do as task `Restart` not just clicking it
"""
if self.is_in_login_confirm(interval=0):
logger.warning('Login page appeared')
from tasks.login.login import Login
Login(self.config, device=self.device).handle_app_login()
raise HandledError
return False
def ui_goto_main(self):
return self.ui_ensure(destination=page_main)

View File

@ -2,12 +2,12 @@ from module.base.timer import Timer
from module.exception import GameNotRunningError
from module.logger import logger
from tasks.base.page import page_main
from tasks.base.ui import UI
from tasks.login.assets.assets_login import *
from tasks.login.cloud import LoginAndroidCloud
from tasks.rogue.blessing.ui import RogueUI
class Login(UI, LoginAndroidCloud):
class Login(LoginAndroidCloud, RogueUI):
def _handle_app_login(self):
"""
Pages:
@ -71,6 +71,8 @@ class Login(UI, LoginAndroidCloud):
continue
if self.ui_additional():
continue
if self.handle_blessing():
continue
return True

View File

@ -1,16 +1,29 @@
import re
import numpy as np
from module.base.timer import Timer
from module.logger import logger
from module.ocr.ocr import OcrResultButton
from module.ocr.ocr import Ocr, OcrResultButton
from tasks.rogue.assets.assets_rogue_blessing import OCR_ROGUE_BUFF
from tasks.rogue.assets.assets_rogue_bonus import BONUS_BOTTOM_WHITE_BAR, BONUS_CONFIRM
from tasks.rogue.blessing.selector import RogueSelector
from tasks.rogue.blessing.ui import RogueBonusOcr
from tasks.rogue.blessing.utils import is_card_selected
from tasks.rogue.keywords import RogueBonus
class RogueBonusOcr(Ocr):
def after_process(self, result):
result = super().after_process(result)
if self.lang == 'cn':
replace_pattern_dict = {
"[宇宝][宙审]": "宇宙",
}
for pat, replace in replace_pattern_dict.items():
result = re.sub(pat, replace, result)
return result
class RogueBonusSelector(RogueSelector):
def _wait_bonus_page_loaded(self, timer=Timer(0.3, count=1), timeout=Timer(5, count=10)):
timer.reset()

View File

@ -3,7 +3,6 @@ import numpy as np
from module.logger import logger
from module.ocr.keyword import Keyword
from module.ocr.ocr import OcrResultButton
from tasks.rogue.blessing.ui import RogueUI
class RogueSelector:
@ -11,7 +10,7 @@ class RogueSelector:
An Interface used in blessing, curio, and other ui selection in rogue
"""
def __init__(self, main: RogueUI):
def __init__(self, main: "RogueUI"):
self.main = main
self.filter_ = None
self.ocr_results = []

View File

@ -1,26 +1,15 @@
import re
from module.base.utils import area_offset
from module.logger import logger
from module.ocr.ocr import Digit, Ocr, OcrResultButton
from module.ocr.ocr import Digit, OcrResultButton
from tasks.base.ui import UI
from tasks.rogue.assets.assets_rogue_ui import *
from tasks.rogue.assets.assets_rogue_weekly import REWARD_ENTER
from tasks.rogue.blessing.blessing import RogueBlessingSelector
from tasks.rogue.blessing.bonus import RogueBonusSelector
from tasks.rogue.blessing.curio import RogueCurioSelector
from tasks.rogue.keywords import RoguePath
class RogueBonusOcr(Ocr):
def after_process(self, result):
result = super().after_process(result)
if self.lang == 'cn':
replace_pattern_dict = {
"[宇宝][宙审]": "宇宙",
}
for pat, replace in replace_pattern_dict.items():
result = re.sub(pat, replace, result)
return result
class RogueUI(UI):
path: RoguePath
@ -86,3 +75,28 @@ class RogueUI(UI):
self.device.click(BLESSING_CONFIRM)
return True
return False
def handle_blessing(self):
"""
Returns:
bool: If handled
"""
if self.is_page_choose_blessing():
logger.hr('Choose blessing', level=2)
selector = RogueBlessingSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_curio():
logger.hr('Choose curio', level=2)
selector = RogueCurioSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_bonus():
logger.hr('Choose bonus', level=2)
selector = RogueBonusSelector(self)
selector.recognize_and_select()
return True
if self.handle_blessing_popup():
return True
return False

View File

@ -7,9 +7,6 @@ from tasks.map.control.waypoint import Waypoint, ensure_waypoints
from tasks.map.route.base import RouteBase as RouteBase_
from tasks.rogue.assets.assets_rogue_ui import BLESSING_CONFIRM
from tasks.rogue.assets.assets_rogue_weekly import ROGUE_REPORT
from tasks.rogue.blessing.blessing import RogueBlessingSelector
from tasks.rogue.blessing.bonus import RogueBonusSelector
from tasks.rogue.blessing.curio import RogueCurioSelector
from tasks.rogue.event.event import RogueEvent
from tasks.rogue.event.reward import RogueReward
from tasks.rogue.route.exit import RogueExit
@ -45,31 +42,6 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent, RogueReward):
return True
return super().walk_additional()
def handle_blessing(self):
"""
Returns:
bool: If handled
"""
if self.is_page_choose_blessing():
logger.hr('Choose blessing', level=2)
selector = RogueBlessingSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_curio():
logger.hr('Choose curio', level=2)
selector = RogueCurioSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_bonus():
logger.hr('Choose bonus', level=2)
selector = RogueBonusSelector(self)
selector.recognize_and_select()
return True
if self.handle_blessing_popup():
return True
return False
def clear_blessing(self, skip_first_screenshot=True):
"""
Pages: