1
0
mirror of https://github.com/TheFunny/ArisuAutoSweeper synced 2026-06-09 20:04:52 +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
+8 -7
View File
@@ -1,14 +1,14 @@
import re
from enum import Flag
from module.base.timer import Timer
from module.exception import RequestHumanTakeover
from module.logger import logger
from tasks.base.assets.assets_base_page import BACK
from tasks.base.assets.assets_base_page import SCHEDULE_CHECK
from tasks.base.page import page_schedule
from tasks.schedule.ui import ScheduleUI
from tasks.base.assets.assets_base_page import SCHEDULE_CHECK
import re
class ScheduleStatus(Flag):
OCR = 0
@@ -18,7 +18,7 @@ class ScheduleStatus(Flag):
FINISH = 4
class Schedule(ScheduleUI):
class Schedule(ScheduleUI):
@property
def schedule_info(self):
info = []
@@ -28,7 +28,8 @@ class Schedule(ScheduleUI):
for choice in choices:
location, classrooms = schedule_config[choice]["Location"], schedule_config[choice]["Classrooms"]
if location == "None" or not classrooms or (isinstance(classrooms, str) and classrooms.replace(" ", "") == ""):
if location == "None" or not classrooms or (
isinstance(classrooms, str) and classrooms.replace(" ", "") == ""):
continue
elif isinstance(classrooms, int):
classrooms_list = [str(classrooms)]
@@ -39,7 +40,7 @@ class Schedule(ScheduleUI):
classrooms_list = []
# tried to convert to set to remove duplicates but doesn't maintain order
[classrooms_list.append(x) for x in classrooms if x not in classrooms_list]
if self.valid_classroom(classrooms_list):
info.append([location, classrooms_list])
else:
@@ -57,7 +58,7 @@ class Schedule(ScheduleUI):
if not 1 <= int(classroom) <= 9:
return False
return True
@property
def valid_task(self) -> list:
task = self.schedule_info
@@ -131,4 +132,4 @@ class Schedule(ScheduleUI):
if status == ScheduleStatus.FINISH:
break
self.config.task_delay(server_update=True)
self.config.task_delay(server_update=True)
+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
+11 -9
View File
@@ -1,17 +1,19 @@
from module.base.timer import Timer
import numpy as np
from module.base.decorator import Config
from module.base.timer import Timer
from module.logger import logger
from module.ocr.ocr import DigitCounter
from tasks.base.ui import UI
from tasks.base.assets.assets_base_page import SCHEDULE_CHECK
from tasks.base.ui import UI
from tasks.schedule.assets.assets_schedule import *
from tasks.schedule.scroll_select import ScrollSelect
import numpy as np
SCROLL_SELECT = ScrollSelect(window_button=SCROLL, first_item_button=FIRST_ITEM, expected_button=LOCATIONS, clickx=1116)
xs = np.linspace(299, 995, 3, dtype=int)
ys = np.linspace(268, 573, 3, dtype=int)
class ScheduleUI(UI):
@Config.when(Emulator_GameLanguage='jp')
def set_clickx(self):
@@ -20,7 +22,7 @@ class ScheduleUI(UI):
@Config.when(Emulator_GameLanguage=None)
def set_clickx(self):
pass
def select_then_check(self, dest_enter: ButtonWrapper, dest_check: ButtonWrapper):
timer = Timer(8, 10).start()
while 1:
@@ -30,10 +32,10 @@ class ScheduleUI(UI):
timer.reset()
if self.appear(dest_check):
return True
if timer.reached():
return False
def click_then_check(self, coords, dest_check: ButtonWrapper):
click_coords = self.device.click_methods.get(self.config.Emulator_ControlMethod, self.device.click_adb)
timer = Timer(3, 2).start()
@@ -47,14 +49,14 @@ class ScheduleUI(UI):
pass
if timer.reached():
return False
def enter_location(self, location):
SCROLL_SELECT.select_location(self, location)
if not self.appear(LOCATIONS):
logger.error("Unable to navigate to page for location {}".format(location + 1))
return False
return self.select_then_check(LOCATIONS, LOCATIONS_POPUP)
def select_classrooms(self, ticket, classrooms):
for classroom in classrooms:
if ticket == 0:
@@ -86,5 +88,5 @@ class ScheduleUI(UI):
logger.warning('Invalid ticket')
return False
logger.attr('ScheduleTicket', ticket)
#self.config.stored.BountyTicket.set(ticket)
# self.config.stored.BountyTicket.set(ticket)
return ticket