Add: Map buttons and technique points

This commit is contained in:
LmeSzinc 2023-06-28 02:03:23 +08:00
parent 8bdb9a4e77
commit 2ae3dac16d
11 changed files with 177 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -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),
),
)

View File

@ -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