From 1f75eb3bf1660b2902b8dae0028f7a23b372c92d Mon Sep 17 00:00:00 2001 From: moesnow <11678347+moesnow@users.noreply.github.com> Date: Sat, 14 Oct 2023 11:10:43 +0800 Subject: [PATCH] perf: sleep --- assets/config/screens.json | 6 ++++++ module/automation/automation.py | 1 - module/screen/screen.py | 4 +++- tasks/power/power.py | 4 ++-- tasks/reward/dispatch.py | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/assets/config/screens.json b/assets/config/screens.json index c0b33604..d9d1f3bf 100644 --- a/assets/config/screens.json +++ b/assets/config/screens.json @@ -95,6 +95,12 @@ "image", 0.95 ] + }, + { + "action": "time.sleep", + "args": [ + 1 + ] } ] }, diff --git a/module/automation/automation.py b/module/automation/automation.py index a4d7aedc..133d4004 100644 --- a/module/automation/automation.py +++ b/module/automation/automation.py @@ -217,7 +217,6 @@ def click_element_with_pos(self, coordinates, offset=(0, 0), action="click"): (left, top), (right, bottom) = coordinates x = (left + right) // 2 + offset[0] y = (top + bottom) // 2 + offset[1] - time.sleep(0.5) if action == "click": self.mouse_click(x, y) elif action == "down": diff --git a/module/screen/screen.py b/module/screen/screen.py index e47b30ec..7f3e0940 100644 --- a/module/screen/screen.py +++ b/module/screen/screen.py @@ -191,10 +191,12 @@ def change_to(self, target_screen, max_recursion=2): if action["target_screen"] == next_screen][0] self.perform_operations(operations) - for i in range(10): + for i in range(20): logger.debug(_("等待:{next_screen}").format(next_screen=self.get_name(next_screen))) if self.check_screen(next_screen): break + else: + time.sleep(0.5) if self.current_screen != next_screen: if max_recursion > 0: diff --git a/tasks/power/power.py b/tasks/power/power.py index d7e19e0d..41702099 100644 --- a/tasks/power/power.py +++ b/tasks/power/power.py @@ -210,10 +210,10 @@ def run_instances(instance_type, instance_name, power_need, number): screen.change_to('guide3') instance_type_crop = (262.0 / 1920, 289.0 / 1080, 422.0 / 1920, 624.0 / 1080) - if not auto.click_element(instance_type, "text", crop=instance_type_crop, take_screenshot=False): + if not auto.click_element(instance_type, "text", crop=instance_type_crop): if auto.click_element("侵蚀隧洞", "text", max_retries=10, crop=instance_type_crop): auto.mouse_scroll(12, -1) - auto.click_element(instance_type, "text", crop=instance_type_crop, take_screenshot=True) + auto.click_element(instance_type, "text", crop=instance_type_crop) # 截图过快会导致结果不可信 time.sleep(1) diff --git a/tasks/reward/dispatch.py b/tasks/reward/dispatch.py index 04b4eb4c..e4b95402 100644 --- a/tasks/reward/dispatch.py +++ b/tasks/reward/dispatch.py @@ -47,4 +47,4 @@ def _click_complete_dispatch(crop): # width, height = auto.get_image_info("./assets/images/dispatch/reward.png") # offset = (-2 * width, 2 * height) offset = (-34, 34) # 以后改相对坐标偏移 - return auto.click_element("./assets/images/dispatch/reward.png", "image", 0.9, max_retries=5, offset=offset, crop=crop) + return auto.click_element("./assets/images/dispatch/reward.png", "image", 0.9, max_retries=8, offset=offset, crop=crop)