diff --git a/assets/share/map/control/A_BUTTON.png b/assets/share/map/control/A_BUTTON.png new file mode 100644 index 000000000..46e8a9f15 Binary files /dev/null and b/assets/share/map/control/A_BUTTON.png differ diff --git a/assets/share/map/control/E_BUTTON.png b/assets/share/map/control/E_BUTTON.png new file mode 100644 index 000000000..3fe31de38 Binary files /dev/null and b/assets/share/map/control/E_BUTTON.png differ diff --git a/assets/share/map/control/JOYSTICK.png b/assets/share/map/control/JOYSTICK.png new file mode 100644 index 000000000..1907050a9 Binary files /dev/null and b/assets/share/map/control/JOYSTICK.png differ diff --git a/assets/share/map/control/RUN_BUTTON.png b/assets/share/map/control/RUN_BUTTON.png new file mode 100644 index 000000000..d6e54c896 Binary files /dev/null and b/assets/share/map/control/RUN_BUTTON.png differ diff --git a/assets/share/map/control/TECHNIQUE_POINT_1.png b/assets/share/map/control/TECHNIQUE_POINT_1.png new file mode 100644 index 000000000..30479efbe Binary files /dev/null and b/assets/share/map/control/TECHNIQUE_POINT_1.png differ diff --git a/assets/share/map/control/TECHNIQUE_POINT_2.png b/assets/share/map/control/TECHNIQUE_POINT_2.png new file mode 100644 index 000000000..76f3d7197 Binary files /dev/null and b/assets/share/map/control/TECHNIQUE_POINT_2.png differ diff --git a/assets/share/map/control/TECHNIQUE_POINT_3.png b/assets/share/map/control/TECHNIQUE_POINT_3.png new file mode 100644 index 000000000..0e2c7fa35 Binary files /dev/null and b/assets/share/map/control/TECHNIQUE_POINT_3.png differ diff --git a/assets/share/map/control/TECHNIQUE_POINT_4.png b/assets/share/map/control/TECHNIQUE_POINT_4.png new file mode 100644 index 000000000..1adda0efa Binary files /dev/null and b/assets/share/map/control/TECHNIQUE_POINT_4.png differ diff --git a/assets/share/map/control/TECHNIQUE_POINT_5.png b/assets/share/map/control/TECHNIQUE_POINT_5.png new file mode 100644 index 000000000..5fcf8b4ba Binary files /dev/null and b/assets/share/map/control/TECHNIQUE_POINT_5.png differ diff --git a/tasks/map/assets/assets_map_control.py b/tasks/map/assets/assets_map_control.py new file mode 100644 index 000000000..a0782a019 --- /dev/null +++ b/tasks/map/assets/assets_map_control.py @@ -0,0 +1,95 @@ +from module.base.button import Button, ButtonWrapper + +# This file was auto-generated, do not modify it manually. To generate: +# ``` python -m dev_tools.button_extract ``` + +A_BUTTON = ButtonWrapper( + name='A_BUTTON', + share=Button( + file='./assets/share/map/control/A_BUTTON.png', + area=(998, 508, 1078, 588), + search=(978, 488, 1098, 608), + color=(85, 86, 89), + button=(998, 508, 1078, 588), + ), +) +E_BUTTON = ButtonWrapper( + name='E_BUTTON', + share=Button( + file='./assets/share/map/control/E_BUTTON.png', + area=(875, 583, 944, 650), + search=(855, 563, 964, 670), + color=(67, 68, 71), + button=(875, 583, 944, 650), + ), +) +JOYSTICK = ButtonWrapper( + name='JOYSTICK', + share=Button( + file='./assets/share/map/control/JOYSTICK.png', + area=(234, 546, 262, 574), + search=(214, 526, 282, 594), + color=(43, 48, 62), + button=(234, 546, 262, 574), + ), +) +RUN_BUTTON = ButtonWrapper( + name='RUN_BUTTON', + share=Button( + file='./assets/share/map/control/RUN_BUTTON.png', + area=(1125, 582, 1191, 651), + search=(1105, 562, 1211, 671), + color=(73, 76, 83), + button=(1125, 582, 1191, 651), + ), +) +TECHNIQUE_POINT_1 = ButtonWrapper( + name='TECHNIQUE_POINT_1', + share=Button( + file='./assets/share/map/control/TECHNIQUE_POINT_1.png', + area=(854, 594, 867, 607), + search=(834, 574, 887, 627), + color=(149, 141, 186), + button=(854, 594, 867, 607), + ), +) +TECHNIQUE_POINT_2 = ButtonWrapper( + name='TECHNIQUE_POINT_2', + share=Button( + file='./assets/share/map/control/TECHNIQUE_POINT_2.png', + area=(862, 578, 876, 592), + search=(842, 558, 896, 612), + color=(139, 132, 174), + button=(862, 578, 876, 592), + ), +) +TECHNIQUE_POINT_3 = ButtonWrapper( + name='TECHNIQUE_POINT_3', + share=Button( + file='./assets/share/map/control/TECHNIQUE_POINT_3.png', + area=(875, 566, 889, 580), + search=(855, 546, 909, 600), + color=(138, 130, 173), + button=(875, 566, 889, 580), + ), +) +TECHNIQUE_POINT_4 = ButtonWrapper( + name='TECHNIQUE_POINT_4', + share=Button( + file='./assets/share/map/control/TECHNIQUE_POINT_4.png', + area=(891, 559, 905, 573), + search=(871, 539, 925, 593), + color=(138, 130, 173), + button=(891, 559, 905, 573), + ), +) +TECHNIQUE_POINT_5 = ButtonWrapper( + name='TECHNIQUE_POINT_5', + share=Button( + file='./assets/share/map/control/TECHNIQUE_POINT_5.png', + area=(908, 559, 921, 573), + search=(888, 539, 941, 593), + color=(71, 72, 77), + button=(908, 559, 921, 573), + ), +) diff --git a/tasks/map/control/joystick.py b/tasks/map/control/joystick.py new file mode 100644 index 000000000..77ced0dbd --- /dev/null +++ b/tasks/map/control/joystick.py @@ -0,0 +1,82 @@ +from functools import cached_property + +from module.base.timer import Timer +from module.logger import logger +from tasks.base.ui import UI +from tasks.map.assets.assets_map_control import * + + +class MapControlJoystick(UI): + _map_A_timer = Timer(1) + _map_E_timer = Timer(1) + _map_run_timer = Timer(1) + + @cached_property + def joystick_center(self) -> tuple[float, float]: + x1, y1, x2, y2 = JOYSTICK.area + return (x1 + x2) / 2, (y1 + y2) / 2 + + def map_get_technique_points(self): + """ + Returns: + int: 0 to 5. + """ + points = [ + self.image_color_count(button, color=(255, 255, 255), threshold=221, count=20) + for button in [ + TECHNIQUE_POINT_1, + TECHNIQUE_POINT_2, + TECHNIQUE_POINT_3, + TECHNIQUE_POINT_4, + TECHNIQUE_POINT_5, + ] + ] + count = sum(points) + logger.attr('TechniquePoints', count) + return count + + def handle_map_A(self): + """ + Simply clicking A with an interval of 1s, no guarantee of success. + + Returns: + bool: If clicked. + """ + if self._map_A_timer.reached(): + self.device.click(A_BUTTON) + self._map_A_timer.reset() + return True + + return False + + def handle_map_E(self): + """ + Simply clicking E with an interval of 1s, no guarantee of success. + Note that E cannot be released if technique points ran out. + + Returns: + bool: If clicked. + """ + if self._map_E_timer.reached(): + self.device.click(E_BUTTON) + self._map_E_timer.reset() + return True + + return False + + def handle_map_run(self): + """ + Keep character running. + Note that RUN button can only be clicked when character is moving. + + Returns: + bool: If clicked. + """ + is_running = self.image_color_count(RUN_BUTTON, color=(208, 183, 138), threshold=221, count=100) + + if not is_running and self._map_run_timer.reached(): + self.device.click(RUN_BUTTON) + self._map_run_timer.reset() + return True + + return False