Add: Decorators to lock rotation

This commit is contained in:
LmeSzinc 2023-10-23 23:48:23 +08:00
parent e1903f0ed4
commit 7a14d819cd
9 changed files with 91 additions and 26 deletions

View File

@ -356,6 +356,9 @@ class RouteDetect:
for row in imp: for row in imp:
if row not in head: if row not in head:
content = row + '\n' + content content = row + '\n' + content
content = content.replace(
'from tasks.rogue.route.base import locked',
'from tasks.map.route.base import locked')
# Replace or add routes # Replace or add routes
routes.create_index('route') routes.create_index('route')
for waypoints in routes.indexes.values(): for waypoints in routes.indexes.values():
@ -404,8 +407,9 @@ class RouteDetect:
content = new content = new
# Format # Format
content = re.sub(r'[\n ]+ def', '\n\n def', content, re.DOTALL) content = re.sub(r'[\n ]+ def', '\n\n def', content)
content = content.rstrip('\n') + '\n' content = content.rstrip('\n') + '\n'
content = re.sub(r' (@[a-zA-Z0-9_().]+)[\n ]+ def', r' \1\n def', content)
# Write # Write
with open(file, 'w', encoding='utf-8', newline='') as f: with open(file, 'w', encoding='utf-8', newline='') as f:
f.write(content) f.write(content)

View File

@ -1,14 +1,12 @@
from tasks.map.control.waypoint import Waypoint from tasks.map.control.waypoint import Waypoint
from tasks.map.keywords.plane import Herta_StorageZone from tasks.map.keywords.plane import Herta_StorageZone
from tasks.map.route.base import locked_position
from tasks.rogue.route.base import RouteBase from tasks.rogue.route.base import RouteBase
class Route(RouteBase): class Route(RouteBase):
def map_init(self, *args, **kwargs): @locked_position
super().map_init(*args, **kwargs)
self.minimap.init_position(self.minimap.position, locked=True)
def Herta_StorageZone_F1_X477Y233(self): def Herta_StorageZone_F1_X477Y233(self):
""" """
| Waypoint | Position | Direction | Rotation | | Waypoint | Position | Direction | Rotation |

View File

@ -1,15 +1,12 @@
from tasks.map.control.waypoint import Waypoint from tasks.map.control.waypoint import Waypoint
from tasks.map.keywords.plane import Luofu_Cloudford from tasks.map.keywords.plane import Luofu_Cloudford
from tasks.map.route.base import locked_rotation
from tasks.rogue.route.base import RouteBase from tasks.rogue.route.base import RouteBase
class Route(RouteBase): class Route(RouteBase):
def map_init(self, *args, **kwargs): @locked_rotation(0)
super().map_init(*args, **kwargs)
# Blue triangle on blue sky, high error rate
self.minimap.lock_rotation(0)
def Luofu_Cloudford_F1_X337Y1003(self): def Luofu_Cloudford_F1_X337Y1003(self):
""" """
| Waypoint | Position | Direction | Rotation | | Waypoint | Position | Direction | Rotation |

View File

@ -1,15 +1,12 @@
from tasks.map.control.waypoint import Waypoint from tasks.map.control.waypoint import Waypoint
from tasks.map.keywords.plane import Luofu_StargazerNavalia from tasks.map.keywords.plane import Luofu_StargazerNavalia
from tasks.map.route.base import locked_rotation
from tasks.rogue.route.base import RouteBase from tasks.rogue.route.base import RouteBase
class Route(RouteBase): class Route(RouteBase):
def map_init(self, *args, **kwargs): @locked_rotation(90)
super().map_init(*args, **kwargs)
# Blue triangle on blue sky, high error rate
self.minimap.lock_rotation(90)
def Luofu_StargazerNavalia_F1_X617Y511(self): def Luofu_StargazerNavalia_F1_X617Y511(self):
""" """
| Waypoint | Position | Direction | Rotation | | Waypoint | Position | Direction | Rotation |

View File

@ -1,5 +1,6 @@
from tasks.map.control.waypoint import Waypoint from tasks.map.control.waypoint import Waypoint
from tasks.map.keywords.plane import Luofu_ScalegorgeWaterscape from tasks.map.keywords.plane import Luofu_ScalegorgeWaterscape
from tasks.map.route.base import locked_rotation
from tasks.rogue.route.base import RouteBase from tasks.rogue.route.base import RouteBase
@ -20,18 +21,19 @@ class Route(RouteBase):
self.clear_event(event) self.clear_event(event)
# ===== End of generated waypoints ===== # ===== End of generated waypoints =====
@locked_rotation(180)
def Luofu_ScalegorgeWaterscape_F1_X619Y387(self): def Luofu_ScalegorgeWaterscape_F1_X619Y387(self):
""" """
| Waypoint | Position | Direction | Rotation | | Waypoint | Position | Direction | Rotation |
| -------- | ------------------------- | --------- | -------- | | -------- | ------------------------- | --------- | -------- |
| spawn | Waypoint((619.4, 387.3)), | 190.1 | 184 | | spawn | Waypoint((619.4, 387.3)), | 190.1 | 184 |
| item | Waypoint((612.9, 413.0)), | 222.0 | 214 | | item | Waypoint((626.2, 408.2)), | 157.2 | 151 |
| event | Waypoint((622.3, 422.5)), | 190.1 | 186 | | event | Waypoint((622.3, 422.5)), | 190.1 | 186 |
| exit | Waypoint((619.0, 423.6)), | 190.1 | 184 | | exit | Waypoint((619.0, 423.6)), | 190.1 | 184 |
""" """
self.map_init(plane=Luofu_ScalegorgeWaterscape, floor="F1", position=(619.4, 387.3)) self.map_init(plane=Luofu_ScalegorgeWaterscape, floor="F1", position=(619.4, 387.3))
self.register_domain_exit(Waypoint((619.0, 423.6)), end_rotation=184) self.register_domain_exit(Waypoint((619.0, 423.6)), end_rotation=184)
item = Waypoint((612.9, 413.0)) item = Waypoint((626.2, 408.2))
event = Waypoint((622.3, 422.5)) event = Waypoint((622.3, 422.5))
self.clear_item(item) self.clear_item(item)

View File

@ -1,14 +1,12 @@
from tasks.map.control.waypoint import Waypoint from tasks.map.control.waypoint import Waypoint
from tasks.map.keywords.plane import Luofu_ArtisanshipCommission from tasks.map.keywords.plane import Luofu_ArtisanshipCommission
from tasks.map.route.base import locked_position
from tasks.rogue.route.base import RouteBase from tasks.rogue.route.base import RouteBase
class Route(RouteBase): class Route(RouteBase):
def map_init(self, *args, **kwargs): @locked_position
super().map_init(*args, **kwargs)
self.minimap.init_position(self.minimap.position, locked=True)
def Luofu_ArtisanshipCommission_F1_X299Y863(self): def Luofu_ArtisanshipCommission_F1_X299Y863(self):
""" """
| Waypoint | Position | Direction | Rotation | | Waypoint | Position | Direction | Rotation |

View File

@ -1,14 +1,13 @@
from tasks.map.control.waypoint import Waypoint from tasks.map.control.waypoint import Waypoint
from tasks.map.keywords.plane import Luofu_ScalegorgeWaterscape from tasks.map.keywords.plane import Luofu_ScalegorgeWaterscape
from tasks.map.route.base import locked_position, locked_rotation
from tasks.rogue.route.base import RouteBase from tasks.rogue.route.base import RouteBase
class Route(RouteBase): class Route(RouteBase):
def map_init(self, *args, **kwargs): @locked_position
super().map_init(*args, **kwargs) @locked_rotation(270)
self.minimap.init_position(self.minimap.position, locked=True)
def Luofu_ScalegorgeWaterscape_F1_X701Y321(self): def Luofu_ScalegorgeWaterscape_F1_X701Y321(self):
""" """
| Waypoint | Position | Direction | Rotation | | Waypoint | Position | Direction | Rotation |

View File

@ -79,11 +79,13 @@ class Minimap(MapResource):
self.rotation_locked = None self.rotation_locked = None
def lock_direction(self, degree: int | float): def lock_direction(self, degree: int | float):
logger.info(f'Lock direction: {degree}')
self.direction_locked = degree self.direction_locked = degree
self.direction = degree self.direction = degree
self.direction_similarity = 0. self.direction_similarity = 0.
def lock_rotation(self, degree: int | float): def lock_rotation(self, degree: int | float):
logger.info(f'Lock rotation: {degree}')
self.rotation_locked = degree self.rotation_locked = degree
self.rotation = degree self.rotation = degree
self.rotation_confidence = 0. self.rotation_confidence = 0.

View File

@ -8,6 +8,9 @@ class RouteBase(MapControl):
Base class of `Route` Base class of `Route`
Every `Route` class must implement method `route()` Every `Route` class must implement method `route()`
""" """
registered_locked_position = None
registered_locked_direction = None
registered_locked_rotation = None
def route_example(self): def route_example(self):
""" """
@ -47,10 +50,75 @@ class RouteBase(MapControl):
self.minimap.set_plane(plane, floor=floor) self.minimap.set_plane(plane, floor=floor)
if position is not None: if position is not None:
self.minimap.init_position(position) self.minimap.init_position(
position=position,
locked=self.registered_locked_position is not None
)
if self.registered_locked_direction is not None:
self.minimap.lock_direction(self.registered_locked_direction)
if self.registered_locked_rotation is not None:
self.minimap.lock_rotation(self.registered_locked_rotation)
self.registered_locked_position = None
self.registered_locked_direction = None
self.registered_locked_rotation = None
def before_route(self): def before_route(self):
pass pass
def after_route(self): def after_route(self):
pass pass
def locked_position(function):
"""
Examples:
@locked_position
def Luofu_ScalegorgeWaterscape_F1_X619Y387(self):
pass # Search area will be locked
"""
def wrapper(self: RouteBase, *args, **kwargs):
self.registered_locked_position = True
result = function(self, *args, **kwargs)
return result
return wrapper
def locked_direction(degree: int | float):
"""
Examples:
@locked_direction(270)
def Luofu_ScalegorgeWaterscape_F1_X619Y387(self):
pass # Direction will be locked to 270
"""
def locker(function):
def wrapper(self: RouteBase, *args, **kwargs):
self.registered_locked_direction = degree
result = function(self, *args, **kwargs)
return result
return wrapper
return locker
def locked_rotation(degree: int | float):
"""
Examples:
@locked_rotation(270)
def Luofu_ScalegorgeWaterscape_F1_X619Y387(self):
pass # Rotation will be locked to 270
"""
def locker(function):
def wrapper(self: RouteBase, *args, **kwargs):
self.registered_locked_rotation = degree
result = function(self, *args, **kwargs)
return result
return wrapper
return locker