Refactor: Remove use_fast parameter

This commit is contained in:
LmeSzinc 2023-07-10 22:20:35 +08:00
parent 866612345f
commit f12e18107f
5 changed files with 34 additions and 27 deletions

View File

@ -74,13 +74,14 @@ class DraggableList:
# logger.warning(f'Row "{row}" does not belong to {self}')
return 0
def keyword2button(self, row: Keyword) -> Optional[OcrResultButton]:
def keyword2button(self, row: Keyword, show_warning=True) -> Optional[OcrResultButton]:
for button in self.cur_buttons:
if button == row:
return button
logger.warning(f'Keyword {row} is not in current rows of {self}')
logger.warning(f'Current rows: {self.cur_buttons}')
if show_warning:
logger.warning(f'Keyword {row} is not in current rows of {self}')
logger.warning(f'Current rows: {self.cur_buttons}')
return None
def load_rows(self, main: ModuleBase):

View File

@ -1,5 +1,4 @@
from module.logger import logger
from tasks.base.page import page_main
from tasks.dungeon.keywords import KEYWORDS_DUNGEON_LIST
from tasks.forgotten_hall.keywords import KEYWORDS_FORGOTTEN_HALL_STAGE
from tasks.forgotten_hall.ui import ForgottenHallUI
@ -25,7 +24,7 @@ class UseTechniqueUI(MapControlJoystick, ForgottenHallUI):
break
self.handle_map_E()
def use_technique(self, count: int, skip_first_screenshot=True):
def use_technique(self, count: int = 2, skip_first_screenshot=True):
"""
Args:
skip_first_screenshot:
@ -41,7 +40,6 @@ class UseTechniqueUI(MapControlJoystick, ForgottenHallUI):
out: page_forgotten_hall, FORGOTTEN_HALL_CHECKED
"""
logger.hr('Use techniques', level=2)
self.ui_ensure(page_main)
self.stage_goto(KEYWORDS_DUNGEON_LIST.The_Last_Vestiges_of_Towering_Citadel,
KEYWORDS_FORGOTTEN_HALL_STAGE.Stage_1)
self._choose_first_character()
@ -49,3 +47,7 @@ class UseTechniqueUI(MapControlJoystick, ForgottenHallUI):
self._use_technique(count, skip_first_screenshot=skip_first_screenshot)
self.exit_dungeon()
self.ui_goto_main()
if __name__ == '__main__':
self = UseTechniqueUI('alas')
self.device.screenshot()
self.use_technique(2)

View File

@ -1,7 +1,7 @@
from module.base.utils import area_offset
from module.logger import logger
from tasks.combat.combat import Combat
from tasks.dungeon.keywords import DungeonList, KEYWORDS_DUNGEON_LIST
from tasks.dungeon.keywords import DungeonList, KEYWORDS_DUNGEON_LIST, KEYWORDS_DUNGEON_TAB
from tasks.dungeon.ui import DungeonUI
@ -13,6 +13,7 @@ class Dungeon(DungeonUI, Combat):
team = self.config.Dungeon_Team
# Run
self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Survival_Index)
if not self.dungeon_goto(dungeon):
logger.error('Please check you dungeon settings')
self.config.Scheduler_Enable = False
@ -20,6 +21,7 @@ class Dungeon(DungeonUI, Combat):
if dungeon == KEYWORDS_DUNGEON_LIST.Stagnant_Shadow_Blaze:
if self.handle_destructible_around_blaze():
self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Survival_Index)
self.dungeon_goto(dungeon)
self.combat(team)

View File

@ -218,22 +218,17 @@ class DungeonUI(UI):
logger.info('DungeonNav row Forgotten_Hall stabled')
return True
def _dungeon_nav_goto(self, dungeon: DungeonList, use_fast=False, skip_first_screenshot=True):
def _dungeon_nav_goto(self, dungeon: DungeonList, skip_first_screenshot=True):
"""
Equivalent to `DUNGEON_NAV_LIST.select_row(dungeon.dungeon_nav, main=self)`
but with tricks to be faster
Args:
dungeon:
use_fast: True to use a faster method to navigate but can only start from list top,
False to start from any list states.
skip_first_screenshot:
"""
logger.hr('Dungeon nav goto', level=2)
logger.info(f'Dungeon nav goto {dungeon.dungeon_nav}, use_fast={use_fast}')
if not use_fast:
DUNGEON_NAV_LIST.select_row(dungeon.dungeon_nav, main=self)
return True
logger.info(f'Dungeon nav goto {dungeon.dungeon_nav}')
# Wait rows
while 1:
@ -245,6 +240,16 @@ class DungeonUI(UI):
if DUNGEON_NAV_LIST.cur_buttons:
break
# Check if it's at the first page.
if DUNGEON_NAV_LIST.keyword2button(KEYWORDS_DUNGEON_NAV.Simulated_Universe, show_warning=False):
# Going to use a faster method to navigate but can only start from list top
logger.info('DUNGEON_NAV_LIST at top')
else:
# To start from any list states.
logger.info('DUNGEON_NAV_LIST not at top')
DUNGEON_NAV_LIST.select_row(dungeon.dungeon_nav, main=self)
return True
# Check the first page
if dungeon.dungeon_nav in [
KEYWORDS_DUNGEON_NAV.Simulated_Universe,
@ -347,20 +352,19 @@ class DungeonUI(UI):
bool: If success
Pages:
in: Any
in: page_guide, Survival_Index
out: COMBAT_PREPARE if success
page_guide if failed
Examples:
from tasks.dungeon.keywords import KEYWORDS_DUNGEON_LIST
self = DungeonUI('alas')
self.device.screenshot()
self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Survival_Index)
self.dungeon_goto(KEYWORDS_DUNGEON_LIST.Calyx_Crimson_Harmony)
"""
logger.hr('Dungeon goto', level=1)
switched = self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Survival_Index)
if dungeon.is_Simulated_Universe:
self._dungeon_nav_goto(dungeon, use_fast=switched)
self._dungeon_nav_goto(dungeon)
pass
self._dungeon_insight(dungeon)
return True
@ -371,14 +375,13 @@ class DungeonUI(UI):
if dungeon.is_Calyx_Golden \
or dungeon.is_Calyx_Crimson \
or dungeon.is_Stagnant_Shadow \
or dungeon.is_Stagnant_Shadow \
or dungeon.is_Cavern_of_Corrosion:
self._dungeon_nav_goto(dungeon, use_fast=switched)
self._dungeon_nav_goto(dungeon)
self._dungeon_insight(dungeon)
self._dungeon_enter(dungeon)
return True
if dungeon.is_Forgotten_Hall:
self._dungeon_nav_goto(dungeon, use_fast=switched)
self._dungeon_nav_goto(dungeon)
self._dungeon_insight(dungeon)
self._dungeon_enter(dungeon, enter_check_button=FORGOTTEN_HALL_CHECK)
return True

View File

@ -10,8 +10,7 @@ from module.ocr.keyword import Keyword
from module.ocr.ocr import Ocr, OcrResultButton
from module.ui.draggable_list import DraggableList
from tasks.base.assets.assets_base_page import FORGOTTEN_HALL_CHECK
from tasks.base.ui import UI
from tasks.dungeon.keywords import DungeonList
from tasks.dungeon.keywords import DungeonList, KEYWORDS_DUNGEON_TAB
from tasks.dungeon.ui import DungeonUI
from tasks.forgotten_hall.assets.assets_forgotten_hall import *
from tasks.forgotten_hall.keywords import *
@ -98,7 +97,7 @@ STAGE_LIST = DraggableStageList("ForgottenHallStageList", keyword_class=Forgotte
check_row_order=False, drag_direction="right")
class ForgottenHallUI(UI):
class ForgottenHallUI(DungeonUI):
def stage_goto(self, forgotten_hall: DungeonList, stage_keyword: ForgottenHallStage):
"""
Examples:
@ -115,8 +114,8 @@ class ForgottenHallUI(UI):
return
if not self.appear(FORGOTTEN_HALL_CHECK):
dungeon_ui = DungeonUI(config=self.config, device=self.device)
dungeon_ui.dungeon_goto(forgotten_hall)
self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Survival_Index)
self.dungeon_goto(forgotten_hall)
STAGE_LIST.select_row(stage_keyword, main=self)
def exit_dungeon(self, skip_first_screenshot=True):