1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2026-06-10 06:54:51 +00:00

style: format

This commit is contained in:
2024-01-15 19:25:15 +08:00
parent e5f91e0c0a
commit e6a3b79733
13 changed files with 124 additions and 115 deletions
+20 -15
View File
@@ -3,8 +3,8 @@ Original Author: sanmusen214(https://github.com/sanmusen214)
Adapted from https://github.com/sanmusen214/BAAH/blob/1.2/modules/AllTask/SubTask/ScrollSelect.py
"""
from module.logger import logger
from module.base.timer import Timer
from module.logger import logger
class ScrollSelect:
@@ -30,7 +30,9 @@ class ScrollSelect:
finalclick: bool
Whether to click on clickx and the last row after the sliding ends
"""
def __init__(self, window_button, first_item_button, expected_button, clickx, swipeoffsetx=-100, finalclick=True) -> None:
def __init__(self, window_button, first_item_button, expected_button, clickx, swipeoffsetx=-100,
finalclick=True) -> None:
# TODO: Actually, only concerned about the height of one element, completely displaying the Y of the first button, completely displaying the Y of the bottom button, the number of complete elements that the window can contain, the height of the last element in the window, and the left offset and response distance.
self.window_starty = window_button.area[1]
self.window_endy = window_button.area[3]
@@ -54,8 +56,9 @@ class ScrollSelect:
main.device.swipe((x1, y1), (x1, y1 - (distance + responsey)), duration=2)
else:
# Effective swipe distance for the Chinese server is 60
main.device.swipe((x1, y1), (x1, int(y1 - (distance + responsey - 4 * (1 + distance / 100)))), duration=1 + distance / 100)
main.device.swipe((x1, y1), (x1, int(y1 - (distance + responsey - 4 * (1 + distance / 100)))),
duration=1 + distance / 100)
def select_location(self, main, target_index) -> None:
click_coords = main.device.click_methods.get(main.config.Emulator_ControlMethod, main.device.click_adb)
logger.info("Scroll and select the {}-th level".format(target_index + 1))
@@ -75,9 +78,9 @@ class ScrollSelect:
# Center point of the target element
target_center_y = start_center_y + self.itemheight * target_index
self.run_until(main,
lambda: click_coords(self.clickx, target_center_y),
lambda: main.appear(self.expected_button),
)
lambda: click_coords(self.clickx, target_center_y),
lambda: main.appear(self.expected_button),
)
else:
# Start scrolling from the gap in the middle of the levels
scroll_start_from_y = self.window_endy - self.itemheight // 2
@@ -86,7 +89,8 @@ class ScrollSelect:
scrolltotal_distance = (target_index - itemcount) * self.itemheight + hiddenlastitemheight
logger.info("Height hidden by the last element: %d" % hiddenlastitemheight)
# First, slide up the hidden part, add a little distance to let the system recognize it as a swipe event
self.compute_swipe(main, self.clickx + self.swipeoffsetx, scroll_start_from_y, hiddenlastitemheight, self.responsey)
self.compute_swipe(main, self.clickx + self.swipeoffsetx, scroll_start_from_y, hiddenlastitemheight,
self.responsey)
logger.info(f"Swipe distance: {hiddenlastitemheight}")
# Update scrolltotal_distance
scrolltotal_distance -= hiddenlastitemheight
@@ -97,18 +101,20 @@ class ScrollSelect:
else:
scroll_distance = (itemcount - 1) * self.itemheight
while scroll_distance <= scrolltotal_distance:
self.compute_swipe(main, self.clickx + self.swipeoffsetx, scroll_start_from_y, scroll_distance, self.responsey)
self.compute_swipe(main, self.clickx + self.swipeoffsetx, scroll_start_from_y, scroll_distance,
self.responsey)
scrolltotal_distance -= scroll_distance
if scrolltotal_distance > 5:
# Last slide
self.compute_swipe(main, self.clickx + self.swipeoffsetx, scroll_start_from_y, scrolltotal_distance, self.responsey)
self.compute_swipe(main, self.clickx + self.swipeoffsetx, scroll_start_from_y, scrolltotal_distance,
self.responsey)
if self.finalclick:
# Click on the last row
self.run_until(main,
lambda: click_coords(self.clickx, self.window_endy - self.itemheight // 2),
lambda: main.appear(self.expected_button)
)
lambda: click_coords(self.clickx, self.window_endy - self.itemheight // 2),
lambda: main.appear(self.expected_button)
)
def run_until(self, main, func1, func2, times=6, sleeptime=1.5) -> bool:
"""
Repeat the execution of func1 up to a maximum of times or until func2 evaluates to True.
@@ -146,4 +152,3 @@ class ScrollSelect:
timer = Timer(0.5).start()
while not timer.reached_and_reset():
pass