mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-13 02:12:14 +00:00
feat: add swipe handling to switch logic
This commit is contained in:
+29
-12
@@ -78,6 +78,7 @@ class Switch:
|
|||||||
"""
|
"""
|
||||||
button = self.get_data(state)['click_button']
|
button = self.get_data(state)['click_button']
|
||||||
main.device.click(button)
|
main.device.click(button)
|
||||||
|
return True
|
||||||
|
|
||||||
def get_data(self, state):
|
def get_data(self, state):
|
||||||
"""
|
"""
|
||||||
@@ -106,6 +107,17 @@ class Switch:
|
|||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def handle_swipe(self, state, main):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
state:
|
||||||
|
main (ModuleBase):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: If swiped
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
def set(self, state, main, skip_first_screenshot=True):
|
def set(self, state, main, skip_first_screenshot=True):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
@@ -120,14 +132,12 @@ class Switch:
|
|||||||
self.get_data(state)
|
self.get_data(state)
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
has_known = False
|
allow_unknown = False
|
||||||
unknown_timer = Timer(5, count=10).start()
|
unknown_timer = Timer(5, count=10).start()
|
||||||
click_timer = Timer(1, count=3)
|
click_timer = Timer(1, count=3)
|
||||||
while 1:
|
swipe_timer = Timer(2, count=6)
|
||||||
if skip_first_screenshot:
|
|
||||||
skip_first_screenshot = False
|
for _ in main.loop(skip_first=skip_first_screenshot):
|
||||||
else:
|
|
||||||
main.device.screenshot()
|
|
||||||
|
|
||||||
# Detect
|
# Detect
|
||||||
current = self.get(main=main)
|
current = self.get(main=main)
|
||||||
@@ -140,20 +150,26 @@ class Switch:
|
|||||||
# Handle additional popups
|
# Handle additional popups
|
||||||
if self.handle_additional(main=main):
|
if self.handle_additional(main=main):
|
||||||
continue
|
continue
|
||||||
|
if swipe_timer.reached():
|
||||||
|
if self.handle_swipe(state, main=main):
|
||||||
|
swipe_timer.reset()
|
||||||
|
# swipe out, may get unknown state
|
||||||
|
allow_unknown = True
|
||||||
|
continue
|
||||||
|
|
||||||
# Warning
|
# Warning
|
||||||
if current == 'unknown':
|
if current == 'unknown':
|
||||||
if unknown_timer.reached():
|
if unknown_timer.reached():
|
||||||
logger.warning(f'Switch {self.name} has states evaluated to unknown, '
|
logger.warning(f'Switch {self.name} has states evaluated to unknown, '
|
||||||
f'asset should be re-verified')
|
f'asset should be re-verified')
|
||||||
has_unknown = True
|
allow_unknown = True
|
||||||
unknown_timer.reset()
|
unknown_timer.reset()
|
||||||
# If unknown_timer never reached, don't click when having an unknown state,
|
# If unknown_timer never reached, don't click when having an unknown state,
|
||||||
# the unknown state is probably the switching animation.
|
# the unknown state is probably the switching animation.
|
||||||
# If unknown_timer reached once, click target state ignoring whether state is unknown or not,
|
# 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.
|
# the unknown state is probably a new state not yet added.
|
||||||
# By ignoring new states, Switch.set() can still switch among known states.
|
# By ignoring new states, Switch.set() can still switch among known states.
|
||||||
if not has_unknown:
|
if not allow_unknown:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
# Known state, reset timer
|
# Known state, reset timer
|
||||||
@@ -172,10 +188,11 @@ class Switch:
|
|||||||
click_state = state
|
click_state = state
|
||||||
else:
|
else:
|
||||||
click_state = current
|
click_state = current
|
||||||
self.click(click_state, main=main)
|
if self.click(click_state, main=main):
|
||||||
changed = True
|
changed = True
|
||||||
click_timer.reset()
|
click_timer.reset()
|
||||||
unknown_timer.reset()
|
unknown_timer.reset()
|
||||||
|
continue
|
||||||
|
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user