mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-07 07:26:46 +08:00
Sync: [ALAS] Refactored Switch.set()
This commit is contained in:
parent
386a2482ad
commit
4ab8337324
@ -53,9 +53,9 @@ class CampaignBase(CampaignBase_):
|
||||
|
||||
map_has_mob_move = True
|
||||
|
||||
def strategy_set_execute(self, formation_index=None, sub_view=None, sub_hunt=None):
|
||||
def strategy_set_execute(self, formation=None, sub_view=None, sub_hunt=None):
|
||||
super().strategy_set_execute(
|
||||
formation_index=formation_index,
|
||||
formation=formation,
|
||||
sub_view=sub_view,
|
||||
sub_hunt=sub_hunt,
|
||||
)
|
||||
|
@ -12,8 +12,8 @@ from module.war_archives.assets import (WAR_ARCHIVES_CAMPAIGN_CHECK,
|
||||
from module.war_archives.dictionary import dic_archives_template
|
||||
|
||||
WAR_ARCHIVES_SWITCH = Switch('War_Archives_switch', is_selector=True)
|
||||
WAR_ARCHIVES_SWITCH.add_status('ex', WAR_ARCHIVES_EX_ON)
|
||||
WAR_ARCHIVES_SWITCH.add_status('sp', WAR_ARCHIVES_SP_ON)
|
||||
WAR_ARCHIVES_SWITCH.add_state('ex', WAR_ARCHIVES_EX_ON)
|
||||
WAR_ARCHIVES_SWITCH.add_state('sp', WAR_ARCHIVES_SP_ON)
|
||||
WAR_ARCHIVES_SCROLL = Scroll(WAR_ARCHIVES_SCROLL, color=(247, 211, 66), name='WAR_ARCHIVES_SCROLL')
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from module.campaign.campaign_base import CampaignBase as CampaignBase_
|
||||
from module.combat.assets import GET_ITEMS_1_RYZA
|
||||
from module.handler.fast_forward import auto_search
|
||||
from module.handler.fast_forward import AUTO_SEARCH
|
||||
from module.handler.assets import MYSTERY_ITEM
|
||||
from module.logger import logger
|
||||
from module.map.map_grids import SelectedGrids
|
||||
@ -62,7 +62,7 @@ class CampaignBase(CampaignBase_):
|
||||
|
||||
# Chapter TH has no map_percentage and no 3_stars
|
||||
if name.startswith('th') or name.startswith('ht'):
|
||||
appear = auto_search.appear(main=self)
|
||||
appear = AUTO_SEARCH.appear(main=self)
|
||||
self.map_is_100_percent_clear = self.map_is_3_stars = self.map_is_threat_safe = appear
|
||||
self.map_has_clear_mode = appear
|
||||
self.map_show_info()
|
||||
|
@ -4,8 +4,8 @@ from module.campaign.campaign_ui import ModeSwitch
|
||||
from module.logger import logger
|
||||
|
||||
MODE_SWITCH_20240725 = ModeSwitch('Mode_switch_20240725', offset=(30, 30))
|
||||
MODE_SWITCH_20240725.add_status('combat', SWITCH_20240725_COMBAT)
|
||||
MODE_SWITCH_20240725.add_status('story', SWITCH_20240725_STORY)
|
||||
MODE_SWITCH_20240725.add_state('combat', SWITCH_20240725_COMBAT)
|
||||
MODE_SWITCH_20240725.add_state('story', SWITCH_20240725_STORY)
|
||||
|
||||
|
||||
class CampaignBase(CampaignBase_):
|
||||
|
@ -4,8 +4,8 @@ from module.campaign.campaign_ui import ModeSwitch
|
||||
from module.logger import logger
|
||||
|
||||
MODE_SWITCH_20240725 = ModeSwitch('Mode_switch_20240725', offset=(30, 30))
|
||||
MODE_SWITCH_20240725.add_status('combat', SWITCH_20240725_COMBAT)
|
||||
MODE_SWITCH_20240725.add_status('story', SWITCH_20240725_STORY)
|
||||
MODE_SWITCH_20240725.add_state('combat', SWITCH_20240725_COMBAT)
|
||||
MODE_SWITCH_20240725.add_state('story', SWITCH_20240725_STORY)
|
||||
|
||||
|
||||
class CampaignBase(CampaignBase_):
|
||||
|
@ -5,8 +5,8 @@ from module.ui.ui import page_event
|
||||
|
||||
|
||||
MODE_SWITCH_20240912 = ModeSwitch('Mode_switch_20240912', is_selector=True, offset=(30, 30))
|
||||
MODE_SWITCH_20240912.add_status('combat', SWITCH_20240725_COMBAT, offset=(444, 4))
|
||||
MODE_SWITCH_20240912.add_status('story', SWITCH_20240725_STORY, offset=(444, 4))
|
||||
MODE_SWITCH_20240912.add_state('combat', SWITCH_20240725_COMBAT, offset=(444, 4))
|
||||
MODE_SWITCH_20240912.add_state('story', SWITCH_20240725_STORY, offset=(444, 4))
|
||||
|
||||
|
||||
class CampaignBase(CampaignBase_):
|
||||
|
@ -7,14 +7,14 @@ from module.map_detection.grid import Grid
|
||||
from module.template.assets import TEMPLATE_ENEMY_BOSS
|
||||
|
||||
MODE_SWITCH_20240725 = ModeSwitch('Mode_switch_20240725', is_selector=True, offset=(30, 30))
|
||||
MODE_SWITCH_20240725.add_status('combat', SWITCH_20240725_COMBAT, offset=(444, 4))
|
||||
MODE_SWITCH_20240725.add_status('story', SWITCH_20240725_STORY, offset=(444, 4))
|
||||
MODE_SWITCH_20240725.add_state('combat', SWITCH_20240725_COMBAT, offset=(444, 4))
|
||||
MODE_SWITCH_20240725.add_state('story', SWITCH_20240725_STORY, offset=(444, 4))
|
||||
|
||||
CHAPTER_SWITCH_20241024 = ModeSwitch('Chapter_switch_20241024', is_selector=True, offset=(30, 30))
|
||||
CHAPTER_SWITCH_20241024.add_status('ab', CHAPTER_20241024_AB)
|
||||
CHAPTER_SWITCH_20241024.add_status('cd', CHAPTER_20241024_CD)
|
||||
CHAPTER_SWITCH_20241024.add_status('sp', CHAPTER_20241024_SP)
|
||||
CHAPTER_SWITCH_20241024.add_status('ex', CHAPTER_20241024_EX)
|
||||
CHAPTER_SWITCH_20241024.add_state('ab', CHAPTER_20241024_AB)
|
||||
CHAPTER_SWITCH_20241024.add_state('cd', CHAPTER_20241024_CD)
|
||||
CHAPTER_SWITCH_20241024.add_state('sp', CHAPTER_20241024_SP)
|
||||
CHAPTER_SWITCH_20241024.add_state('ex', CHAPTER_20241024_EX)
|
||||
|
||||
|
||||
class EventGrid(Grid):
|
||||
|
@ -18,11 +18,11 @@ class ModeSwitch(Switch):
|
||||
|
||||
|
||||
MODE_SWITCH_1 = ModeSwitch('Mode_switch_1', offset=(30, 10))
|
||||
MODE_SWITCH_1.add_status('normal', SWITCH_1_NORMAL)
|
||||
MODE_SWITCH_1.add_status('hard', SWITCH_1_HARD)
|
||||
MODE_SWITCH_1.add_state('normal', SWITCH_1_NORMAL)
|
||||
MODE_SWITCH_1.add_state('hard', SWITCH_1_HARD)
|
||||
MODE_SWITCH_2 = ModeSwitch('Mode_switch_2', offset=(30, 10))
|
||||
MODE_SWITCH_2.add_status('hard', SWITCH_2_HARD)
|
||||
MODE_SWITCH_2.add_status('ex', SWITCH_2_EX)
|
||||
MODE_SWITCH_2.add_state('hard', SWITCH_2_HARD)
|
||||
MODE_SWITCH_2.add_state('ex', SWITCH_2_EX)
|
||||
|
||||
|
||||
class CampaignUI(MapOperation, CampaignEvent, CampaignOcr):
|
||||
|
@ -24,12 +24,12 @@ class CoalitionUI(Combat):
|
||||
"""
|
||||
MODE_SWITCH = Switch('CoalitionMode', offset=(20, 20))
|
||||
if event == 'coalition_20230323':
|
||||
MODE_SWITCH.add_status('story', FROSTFALL_MODE_STORY)
|
||||
MODE_SWITCH.add_status('battle', FROSTFALL_MODE_BATTLE)
|
||||
MODE_SWITCH.add_state('story', FROSTFALL_MODE_STORY)
|
||||
MODE_SWITCH.add_state('battle', FROSTFALL_MODE_BATTLE)
|
||||
elif event == 'coalition_20240627':
|
||||
# Note that switch button are reversed
|
||||
MODE_SWITCH.add_status('story', ACADEMY_MODE_BATTLE)
|
||||
MODE_SWITCH.add_status('battle', ACADEMY_MODE_STORY)
|
||||
MODE_SWITCH.add_state('story', ACADEMY_MODE_BATTLE)
|
||||
MODE_SWITCH.add_state('battle', ACADEMY_MODE_STORY)
|
||||
else:
|
||||
logger.error(f'MODE_SWITCH is not defined in event {event}')
|
||||
raise ScriptError
|
||||
@ -52,11 +52,11 @@ class CoalitionUI(Combat):
|
||||
"""
|
||||
FLEET_SWITCH = Switch('FleetMode', is_selector=True, offset=0) # No offset for color match
|
||||
if event == 'coalition_20230323':
|
||||
FLEET_SWITCH.add_status('single', FROSTFALL_SWITCH_SINGLE)
|
||||
FLEET_SWITCH.add_status('multi', FROSTFALL_SWITCH_MULTI)
|
||||
FLEET_SWITCH.add_state('single', FROSTFALL_SWITCH_SINGLE)
|
||||
FLEET_SWITCH.add_state('multi', FROSTFALL_SWITCH_MULTI)
|
||||
elif event == 'coalition_20240627':
|
||||
FLEET_SWITCH.add_status('single', ACADEMY_SWITCH_SINGLE)
|
||||
FLEET_SWITCH.add_status('multi', ACADEMY_SWITCH_MULTI)
|
||||
FLEET_SWITCH.add_state('single', ACADEMY_SWITCH_SINGLE)
|
||||
FLEET_SWITCH.add_state('multi', ACADEMY_SWITCH_MULTI)
|
||||
else:
|
||||
logger.error(f'FLEET_SWITCH is not defined in event {event}')
|
||||
raise ScriptError
|
||||
|
@ -24,8 +24,8 @@ from module.ui.ui import UI
|
||||
from module.ui_white.assets import REWARD_1_WHITE, REWARD_GOTO_COMMISSION_WHITE
|
||||
|
||||
COMMISSION_SWITCH = Switch('Commission_switch', is_selector=True)
|
||||
COMMISSION_SWITCH.add_status('daily', COMMISSION_DAILY)
|
||||
COMMISSION_SWITCH.add_status('urgent', COMMISSION_URGENT)
|
||||
COMMISSION_SWITCH.add_state('daily', COMMISSION_DAILY)
|
||||
COMMISSION_SWITCH.add_state('urgent', COMMISSION_URGENT)
|
||||
COMMISSION_SCROLL = Scroll(COMMISSION_SCROLL_AREA, color=(247, 211, 66), name='COMMISSION_SCROLL')
|
||||
|
||||
|
||||
|
@ -18,8 +18,8 @@ EQUIPMENT_SCROLL = Scroll(EQUIP_SCROLL, color=(247, 211, 66), name='EQUIP_SCROLL
|
||||
SIM_VALUE = 0.90
|
||||
|
||||
equipping_filter = Switch('Equipping_filter')
|
||||
equipping_filter.add_status('on', check_button=EQUIPPING_ON)
|
||||
equipping_filter.add_status('off', check_button=EQUIPPING_OFF)
|
||||
equipping_filter.add_state('on', check_button=EQUIPPING_ON)
|
||||
equipping_filter.add_state('off', check_button=EQUIPPING_OFF)
|
||||
|
||||
|
||||
class EquipmentChange(Equipment):
|
||||
|
@ -7,15 +7,15 @@ from module.handler.auto_search import AutoSearchHandler
|
||||
from module.logger import logger
|
||||
from module.ui.switch import Switch
|
||||
|
||||
fast_forward = Switch('Fast_Forward')
|
||||
fast_forward.add_status('on', check_button=FAST_FORWARD_ON)
|
||||
fast_forward.add_status('off', check_button=FAST_FORWARD_OFF)
|
||||
fleet_lock = Switch('Fleet_Lock', offset=(5, 20))
|
||||
fleet_lock.add_status('on', check_button=FLEET_LOCKED)
|
||||
fleet_lock.add_status('off', check_button=FLEET_UNLOCKED)
|
||||
auto_search = Switch('Auto_Search', offset=(20, 20))
|
||||
auto_search.add_status('on', check_button=AUTO_SEARCH_ON)
|
||||
auto_search.add_status('off', check_button=AUTO_SEARCH_OFF)
|
||||
FAST_FORWARD = Switch('Fast_Forward')
|
||||
FAST_FORWARD.add_state('on', check_button=FAST_FORWARD_ON)
|
||||
FAST_FORWARD.add_state('off', check_button=FAST_FORWARD_OFF)
|
||||
FLEET_LOCK = Switch('Fleet_Lock', offset=(5, 20))
|
||||
FLEET_LOCK.add_state('on', check_button=FLEET_LOCKED)
|
||||
FLEET_LOCK.add_state('off', check_button=FLEET_UNLOCKED)
|
||||
AUTO_SEARCH = Switch('Auto_Search', offset=(20, 20))
|
||||
AUTO_SEARCH.add_state('on', check_button=AUTO_SEARCH_ON)
|
||||
AUTO_SEARCH.add_state('off', check_button=AUTO_SEARCH_OFF)
|
||||
|
||||
|
||||
def map_files(event):
|
||||
@ -127,9 +127,9 @@ class FastForwardHandler(AutoSearchHandler):
|
||||
# Minor issue here
|
||||
# Using auto_search option because clear mode cannot be detected whether on SP
|
||||
# If user manually turn off auto search, alas can't enable it again
|
||||
self.map_has_clear_mode = auto_search.appear(main=self)
|
||||
self.map_has_clear_mode = AUTO_SEARCH.appear(main=self)
|
||||
else:
|
||||
self.map_has_clear_mode = self.map_is_100_percent_clear and fast_forward.appear(main=self)
|
||||
self.map_has_clear_mode = self.map_is_100_percent_clear and FAST_FORWARD.appear(main=self)
|
||||
|
||||
# Override config
|
||||
if self.map_achieved_star_1:
|
||||
@ -187,8 +187,8 @@ class FastForwardHandler(AutoSearchHandler):
|
||||
self.map_is_2x_book = False
|
||||
pass
|
||||
|
||||
status = 'on' if self.config.Campaign_UseClearMode else 'off'
|
||||
changed = fast_forward.set(status=status, main=self)
|
||||
state = 'on' if self.config.Campaign_UseClearMode else 'off'
|
||||
changed = FAST_FORWARD.set(state, main=self)
|
||||
return changed
|
||||
|
||||
def handle_map_fleet_lock(self, enable=None):
|
||||
@ -201,14 +201,14 @@ class FastForwardHandler(AutoSearchHandler):
|
||||
"""
|
||||
# Fleet lock depends on if it appear on map, not depends on map status.
|
||||
# Because if already in map, there's no map status,
|
||||
if not fleet_lock.appear(main=self):
|
||||
if not FLEET_LOCK.appear(main=self):
|
||||
logger.info('No fleet lock option.')
|
||||
return False
|
||||
|
||||
if enable is None:
|
||||
enable = self.config.Campaign_UseFleetLock
|
||||
status = 'on' if enable else 'off'
|
||||
changed = fleet_lock.set(status=status, main=self)
|
||||
state = 'on' if enable else 'off'
|
||||
changed = FLEET_LOCK.set(state, main=self)
|
||||
|
||||
return changed
|
||||
|
||||
@ -223,13 +223,13 @@ class FastForwardHandler(AutoSearchHandler):
|
||||
# if not self.map_is_clear_mode:
|
||||
# return False
|
||||
|
||||
if not auto_search.appear(main=self):
|
||||
if not AUTO_SEARCH.appear(main=self):
|
||||
logger.info('No auto search option.')
|
||||
self.map_is_auto_search = False
|
||||
return False
|
||||
|
||||
status = 'on' if self.map_is_auto_search else 'off'
|
||||
changed = auto_search.set(status=status, main=self)
|
||||
state = 'on' if self.map_is_auto_search else 'off'
|
||||
changed = AUTO_SEARCH.set(state, main=self)
|
||||
|
||||
return changed
|
||||
|
||||
@ -461,8 +461,8 @@ class FastForwardHandler(AutoSearchHandler):
|
||||
book_check = BOOK_CHECK_AUTO
|
||||
book_box = BOOK_BOX_AUTO
|
||||
|
||||
status = 'on' if self.map_is_2x_book else 'off'
|
||||
if self._set_2x_book_status(status, book_check, book_box):
|
||||
state = 'on' if self.map_is_2x_book else 'off'
|
||||
if self._set_2x_book_status(state, book_check, book_box):
|
||||
self.emotion.map_is_2x_book = self.map_is_2x_book
|
||||
else:
|
||||
self.map_is_2x_book = False
|
||||
|
@ -7,18 +7,18 @@ from module.template.assets import (TEMPLATE_FORMATION_1, TEMPLATE_FORMATION_2,
|
||||
from module.ui.switch import Switch
|
||||
|
||||
# 2023.10.19, icons on one row increased from 2 to 3
|
||||
formation = Switch('Formation', offset=(100, 200))
|
||||
formation.add_status('line_ahead', check_button=FORMATION_1)
|
||||
formation.add_status('double_line', check_button=FORMATION_2)
|
||||
formation.add_status('diamond', check_button=FORMATION_3)
|
||||
FORMATION = Switch('Formation', offset=(100, 200))
|
||||
FORMATION.add_state('line_ahead', check_button=FORMATION_1)
|
||||
FORMATION.add_state('double_line', check_button=FORMATION_2)
|
||||
FORMATION.add_state('diamond', check_button=SUBMARINE_HUNT_ON)
|
||||
|
||||
submarine_hunt = Switch('Submarine_hunt', offset=(200, 200))
|
||||
submarine_hunt.add_status('on', check_button=SUBMARINE_HUNT_ON)
|
||||
submarine_hunt.add_status('off', check_button=SUBMARINE_HUNT_OFF)
|
||||
SUBMARINE_HUNT = Switch('Submarine_hunt', offset=(200, 200))
|
||||
SUBMARINE_HUNT.add_state('on', check_button=SUBMARINE_HUNT_ON)
|
||||
SUBMARINE_HUNT.add_state('off', check_button=SUBMARINE_HUNT_OFF)
|
||||
|
||||
submarine_view = Switch('Submarine_view', offset=(100, 200))
|
||||
submarine_view.add_status('on', check_button=SUBMARINE_VIEW_ON)
|
||||
submarine_view.add_status('off', check_button=SUBMARINE_VIEW_OFF)
|
||||
SUBMARINE_VIEW = Switch('Submarine_view', offset=(100, 200))
|
||||
SUBMARINE_VIEW.add_state('on', check_button=SUBMARINE_VIEW_ON)
|
||||
SUBMARINE_VIEW.add_state('off', check_button=SUBMARINE_VIEW_OFF)
|
||||
|
||||
MOB_MOVE_OFFSET = (120, 200)
|
||||
|
||||
@ -60,20 +60,20 @@ class StrategyHandler(InfoHandler):
|
||||
if not self.appear(STRATEGY_OPENED, offset=200):
|
||||
break
|
||||
|
||||
def strategy_set_execute(self, formation_index=None, sub_view=None, sub_hunt=None):
|
||||
def strategy_set_execute(self, formation=None, sub_view=None, sub_hunt=None):
|
||||
"""
|
||||
Args:
|
||||
formation_index (int): 1-3, or None for don't change
|
||||
formation (str): 'line_ahead', 'double_line', 'diamond', or None for don't change
|
||||
sub_view (bool):
|
||||
sub_hunt (bool):
|
||||
|
||||
Pages:
|
||||
in: STRATEGY_OPENED
|
||||
"""
|
||||
logger.info(f'Strategy set: formation={formation_index}, submarine_view={sub_view}, submarine_hunt={sub_hunt}')
|
||||
logger.info(f'Strategy set: formation={formation}, submarine_view={sub_view}, submarine_hunt={sub_hunt}')
|
||||
|
||||
if formation_index is not None:
|
||||
formation.set(str(formation_index), main=self)
|
||||
if formation is not None:
|
||||
FORMATION.set(formation, main=self)
|
||||
# Disable this until the icon bug of submarine zone is fixed
|
||||
# And don't enable MAP_HAS_DYNAMIC_RED_BORDER when using submarine
|
||||
|
||||
@ -81,13 +81,13 @@ class StrategyHandler(InfoHandler):
|
||||
|
||||
# Don't know when but the game bug was fixed, remove the use of SwitchWithHandler
|
||||
if sub_view is not None:
|
||||
if submarine_view.appear(main=self):
|
||||
submarine_view.set('on' if sub_view else 'off', main=self)
|
||||
if SUBMARINE_VIEW.appear(main=self):
|
||||
SUBMARINE_VIEW.set('on' if sub_view else 'off', main=self)
|
||||
else:
|
||||
logger.warning('Setting up submarine_view but no icon appears')
|
||||
if sub_hunt is not None:
|
||||
if submarine_hunt.appear(main=self):
|
||||
submarine_hunt.set('on' if sub_hunt else 'off', main=self)
|
||||
if SUBMARINE_HUNT.appear(main=self):
|
||||
SUBMARINE_HUNT.set('on' if sub_hunt else 'off', main=self)
|
||||
else:
|
||||
logger.warning('Setting up submarine_hunt but no icon appears')
|
||||
|
||||
@ -110,7 +110,7 @@ class StrategyHandler(InfoHandler):
|
||||
|
||||
self.strategy_open()
|
||||
self.strategy_set_execute(
|
||||
formation_index=expected_formation,
|
||||
formation=expected_formation,
|
||||
sub_view=False,
|
||||
sub_hunt=bool(self.config.Submarine_Fleet) and self.config.Submarine_Mode in ['hunt_only', 'hunt_and_boss']
|
||||
)
|
||||
|
@ -15,12 +15,12 @@ MEOWFFICER_SHIFT_DETECT = Button(
|
||||
name='MEOWFFICER_SHIFT_DETECT')
|
||||
|
||||
SWITCH_LOCK = Switch(name='Meowfficer_Lock', offset=(40, 40))
|
||||
SWITCH_LOCK.add_status(
|
||||
SWITCH_LOCK.add_state(
|
||||
'lock',
|
||||
check_button=MEOWFFICER_APPLY_UNLOCK,
|
||||
click_button=MEOWFFICER_APPLY_LOCK
|
||||
)
|
||||
SWITCH_LOCK.add_status(
|
||||
SWITCH_LOCK.add_state(
|
||||
'unlock',
|
||||
check_button=MEOWFFICER_APPLY_LOCK,
|
||||
click_button=MEOWFFICER_APPLY_UNLOCK
|
||||
@ -175,7 +175,7 @@ class MeowfficerCollect(MeowfficerBase):
|
||||
lock (bool):
|
||||
"""
|
||||
# Apply designated lock status
|
||||
SWITCH_LOCK.set(status='lock' if lock else 'unlock', main=self)
|
||||
SWITCH_LOCK.set('lock' if lock else 'unlock', main=self)
|
||||
|
||||
# Wait until info bar disappears
|
||||
self.ensure_no_info_bar(timeout=1)
|
||||
|
@ -20,8 +20,8 @@ class FleetLockSwitch(Switch):
|
||||
|
||||
|
||||
fleet_lock = FleetLockSwitch('Fleet_Lock', offset=(10, 120))
|
||||
fleet_lock.add_status('on', check_button=OS_FLEET_LOCKED)
|
||||
fleet_lock.add_status('off', check_button=OS_FLEET_UNLOCKED)
|
||||
fleet_lock.add_state('on', check_button=OS_FLEET_LOCKED)
|
||||
fleet_lock.add_state('off', check_button=OS_FLEET_UNLOCKED)
|
||||
|
||||
|
||||
class MapEventHandler(EnemySearchingHandler):
|
||||
@ -306,7 +306,7 @@ class MapEventHandler(EnemySearchingHandler):
|
||||
|
||||
if enable is None:
|
||||
enable = self.config.Campaign_UseFleetLock
|
||||
status = 'on' if enable else 'off'
|
||||
changed = fleet_lock.set(status=status, main=self)
|
||||
state = 'on' if enable else 'off'
|
||||
changed = fleet_lock.set(state, main=self)
|
||||
|
||||
return changed
|
||||
|
@ -12,12 +12,12 @@ from module.ui.setting import Setting
|
||||
from module.ui.switch import Switch
|
||||
|
||||
DOCK_SORTING = Switch('Dork_sorting')
|
||||
DOCK_SORTING.add_status('Ascending', check_button=SORT_ASC, click_button=SORTING_CLICK)
|
||||
DOCK_SORTING.add_status('Descending', check_button=SORT_DESC, click_button=SORTING_CLICK)
|
||||
DOCK_SORTING.add_state('Ascending', check_button=SORT_ASC, click_button=SORTING_CLICK)
|
||||
DOCK_SORTING.add_state('Descending', check_button=SORT_DESC, click_button=SORTING_CLICK)
|
||||
|
||||
DOCK_FAVOURITE = Switch('Favourite_filter')
|
||||
DOCK_FAVOURITE.add_status('on', check_button=COMMON_SHIP_FILTER_ENABLE)
|
||||
DOCK_FAVOURITE.add_status('off', check_button=COMMON_SHIP_FILTER_DISABLE)
|
||||
DOCK_FAVOURITE.add_state('on', check_button=COMMON_SHIP_FILTER_ENABLE)
|
||||
DOCK_FAVOURITE.add_state('off', check_button=COMMON_SHIP_FILTER_DISABLE)
|
||||
|
||||
CARD_GRIDS = ButtonGrid(
|
||||
origin=(93, 76), delta=(164 + 2 / 3, 227), button_shape=(138, 204), grid_shape=(7, 2), name='CARD')
|
||||
|
@ -1,5 +1,4 @@
|
||||
from module.base.base import ModuleBase
|
||||
from module.base.button import Button
|
||||
from module.base.timer import Timer
|
||||
from module.exception import ScriptError
|
||||
from module.logger import logger
|
||||
@ -7,16 +6,15 @@ from module.logger import logger
|
||||
|
||||
class Switch:
|
||||
"""
|
||||
A wrapper to handle switches in game.
|
||||
Set switch status with reties.
|
||||
A wrapper to handle switches in game, switch among states with retries.
|
||||
|
||||
Examples:
|
||||
# Definitions
|
||||
submarine_hunt = Switch('Submarine_hunt', offset=120)
|
||||
submarine_hunt.add_status('on', check_button=SUBMARINE_HUNT_ON)
|
||||
submarine_hunt.add_status('off', check_button=SUBMARINE_HUNT_OFF)
|
||||
submarine_hunt.add_state('on', check_button=SUBMARINE_HUNT_ON)
|
||||
submarine_hunt.add_state('off', check_button=SUBMARINE_HUNT_OFF)
|
||||
|
||||
# Change status to ON
|
||||
# Change state to ON
|
||||
submarine_view.set('on', main=self)
|
||||
"""
|
||||
|
||||
@ -28,23 +26,24 @@ class Switch:
|
||||
For example: | [Daily] | Urgent | -> click -> | Daily | [Urgent] |
|
||||
False if this is a switch, click the switch itself, and it changed in the same position.
|
||||
For example: | [ON] | -> click -> | [OFF] |
|
||||
offset (bool, int, tuple): Global offset in current switch
|
||||
"""
|
||||
self.name = name
|
||||
self.is_choice = is_selector
|
||||
self.is_selector = is_selector
|
||||
self.offset = offset
|
||||
self.status_list = []
|
||||
self.state_list = []
|
||||
|
||||
def add_status(self, status, check_button, click_button=None, offset=0):
|
||||
def add_state(self, state, check_button, click_button=None, offset=0):
|
||||
"""
|
||||
Args:
|
||||
status (str):
|
||||
state (str): State name but cannot use 'unknown' as state name
|
||||
check_button (Button):
|
||||
click_button (Button):
|
||||
offset (bool, int, tuple):
|
||||
"""
|
||||
self.status_list.append({
|
||||
'status': status,
|
||||
if state == 'unknown':
|
||||
raise ScriptError(f'Cannot use "unknown" as state name')
|
||||
self.state_list.append({
|
||||
'state': state,
|
||||
'check_button': check_button,
|
||||
'click_button': click_button if click_button is not None else check_button,
|
||||
'offset': offset if offset else self.offset
|
||||
@ -58,7 +57,7 @@ class Switch:
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
for data in self.status_list:
|
||||
for data in self.state_list:
|
||||
if main.appear(data['check_button'], offset=data['offset']):
|
||||
return True
|
||||
|
||||
@ -70,31 +69,39 @@ class Switch:
|
||||
main (ModuleBase):
|
||||
|
||||
Returns:
|
||||
str: Status name or 'unknown'.
|
||||
str: state name or 'unknown'.
|
||||
"""
|
||||
for data in self.status_list:
|
||||
for data in self.state_list:
|
||||
if main.appear(data['check_button'], offset=data['offset']):
|
||||
return data['status']
|
||||
return data['state']
|
||||
|
||||
return 'unknown'
|
||||
|
||||
def get_data(self, status):
|
||||
def click(self, state, main):
|
||||
"""
|
||||
Args:
|
||||
status (str):
|
||||
state (str):
|
||||
main (ModuleBase):
|
||||
"""
|
||||
button = self.get_data(state)['click_button']
|
||||
main.device.click(button)
|
||||
|
||||
def get_data(self, state):
|
||||
"""
|
||||
Args:
|
||||
state (str):
|
||||
|
||||
Returns:
|
||||
dict: Dictionary in add_status
|
||||
dict: Dictionary in add_state
|
||||
|
||||
Raises:
|
||||
ScriptError: If status invalid
|
||||
ScriptError: If state invalid
|
||||
"""
|
||||
for row in self.status_list:
|
||||
if row['status'] == status:
|
||||
for row in self.state_list:
|
||||
if row['state'] == state:
|
||||
return row
|
||||
|
||||
logger.warning(f'Switch {self.name} received an invalid status {status}')
|
||||
raise ScriptError(f'Switch {self.name} received an invalid status {status}')
|
||||
raise ScriptError(f'Switch {self.name} received an invalid state: {state}')
|
||||
|
||||
def handle_additional(self, main):
|
||||
"""
|
||||
@ -106,21 +113,22 @@ class Switch:
|
||||
"""
|
||||
return False
|
||||
|
||||
def set(self, status, main, skip_first_screenshot=True):
|
||||
def set(self, state, main, skip_first_screenshot=True):
|
||||
"""
|
||||
Args:
|
||||
status (str):
|
||||
state:
|
||||
main (ModuleBase):
|
||||
skip_first_screenshot (bool):
|
||||
|
||||
Returns:
|
||||
bool:
|
||||
bool: If clicked
|
||||
"""
|
||||
self.get_data(status)
|
||||
logger.info(f'{self.name} set to {state}')
|
||||
self.get_data(state)
|
||||
|
||||
counter = 0
|
||||
changed = False
|
||||
warning_show_timer = Timer(5, count=10).start()
|
||||
has_unknown = False
|
||||
unknown_timer = Timer(5, count=10).start()
|
||||
click_timer = Timer(1, count=3)
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
@ -132,31 +140,81 @@ class Switch:
|
||||
current = self.get(main=main)
|
||||
logger.attr(self.name, current)
|
||||
|
||||
# End
|
||||
if current == state:
|
||||
return changed
|
||||
|
||||
# Handle additional popups
|
||||
if self.handle_additional(main=main):
|
||||
continue
|
||||
|
||||
# End
|
||||
if current == status:
|
||||
return changed
|
||||
|
||||
# Warning
|
||||
if current == 'unknown':
|
||||
if warning_show_timer.reached():
|
||||
logger.warning(f'Unknown {self.name} switch')
|
||||
warning_show_timer.reset()
|
||||
if counter >= 1:
|
||||
logger.warning(f'{self.name} switch {status} asset has evaluated to unknown too many times, '
|
||||
f'asset should be re-verified')
|
||||
return False
|
||||
counter += 1
|
||||
continue
|
||||
if unknown_timer.reached():
|
||||
logger.warning(f'Switch {self.name} has states evaluated to unknown, '
|
||||
f'asset should be re-verified')
|
||||
has_unknown = True
|
||||
unknown_timer.reset()
|
||||
# If unknown_timer never reached, don't click when having an unknown state,
|
||||
# the unknown state is probably the switching animation.
|
||||
# If unknown_timer reached once, click target state ignoring whether state is unknown or not,
|
||||
# the unknown state is probably a new state not yet added.
|
||||
# By ignoring new states, Switch.set() can still switch among known states.
|
||||
if not has_unknown:
|
||||
continue
|
||||
else:
|
||||
# Known state, reset timer
|
||||
unknown_timer.reset()
|
||||
|
||||
# Click
|
||||
if click_timer.reached():
|
||||
click_status = status if self.is_choice else current
|
||||
main.device.click(self.get_data(click_status)['click_button'])
|
||||
click_timer.reset()
|
||||
if self.is_selector:
|
||||
# Click target state to switch
|
||||
click_state = state
|
||||
else:
|
||||
# If this is a selector, click on current state to switch to another
|
||||
# But 'unknown' is not clickable, if it is, click target state instead
|
||||
# assuming all selector states share the same position.
|
||||
if current == 'unknown':
|
||||
click_state = state
|
||||
else:
|
||||
click_state = current
|
||||
self.click(click_state, main=main)
|
||||
changed = True
|
||||
click_timer.reset()
|
||||
unknown_timer.reset()
|
||||
|
||||
return changed
|
||||
|
||||
def wait(self, main, skip_first_screenshot=True):
|
||||
"""
|
||||
Wait until any state activated
|
||||
|
||||
Args:
|
||||
main (ModuleBase):
|
||||
skip_first_screenshot:
|
||||
|
||||
Returns:
|
||||
bool: If success
|
||||
"""
|
||||
timeout = Timer(2, count=6).start()
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
main.device.screenshot()
|
||||
|
||||
# Detect
|
||||
current = self.get(main=main)
|
||||
logger.attr(self.name, current)
|
||||
|
||||
# End
|
||||
if current != 'unknown':
|
||||
return True
|
||||
if timeout.reached():
|
||||
logger.warning(f'{self.name} wait activated timeout')
|
||||
return False
|
||||
|
||||
# Handle additional popups
|
||||
if self.handle_additional(main=main):
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user