From ee7cd3958d7ea23384fd86f50b3f85f67225ceac Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:34:12 +0800 Subject: [PATCH] Refactor: Chain calling waypoint methods --- tasks/map/control/control.py | 6 +++--- tasks/map/control/waypoint.py | 32 ++++++++++++++++---------------- tasks/map/minimap/minimap.py | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tasks/map/control/control.py b/tasks/map/control/control.py index f2b95b117..1c2741848 100644 --- a/tasks/map/control/control.py +++ b/tasks/map/control/control.py @@ -357,13 +357,13 @@ if __name__ == '__main__': self.minimap.init_position((519, 359)) # Visit 3 items self.clear_item( - Waypoint.run_2x((587.6, 366.9)), + Waypoint((587.6, 366.9)).run_2x(), ) self.clear_item((575.5, 377.4)) self.clear_item( # Go through arched door - Waypoint.run((581.5, 383.3), threshold=3), - Waypoint.run((575.7, 417.2)), + Waypoint((581.5, 383.3)).run().set_threshold(3), + Waypoint((575.7, 417.2)).run(), ) # Goto boss self.clear_enemy((613.5, 427.3)) diff --git a/tasks/map/control/waypoint.py b/tasks/map/control/waypoint.py index 0c1d5a07c..8cd018999 100644 --- a/tasks/map/control/waypoint.py +++ b/tasks/map/control/waypoint.py @@ -47,29 +47,29 @@ class Waypoint: __repr__ = __str__ - @classmethod - def run_2x(cls, *args, **kwargs) -> "Waypoint": + def run_2x(self) -> "Waypoint": """ Product a Waypoint object with overridden "speed", see Waypoint class for args. """ - kwargs['speed'] = 'run_2x' - return cls(*args, **kwargs) + self.speed = 'run_2x' + return self - @classmethod - def straight_run(cls, *args, **kwargs) -> "Waypoint": - kwargs['speed'] = 'straight_run' - return cls(*args, **kwargs) + def straight_run(self) -> "Waypoint": + self.speed = 'straight_run' + return self - @classmethod - def run(cls, *args, **kwargs) -> "Waypoint": - kwargs['speed'] = 'run' - return cls(*args, **kwargs) + def run(self) -> "Waypoint": + self.speed = 'run' + return self - @classmethod - def walk(cls, *args, **kwargs) -> "Waypoint": - kwargs['speed'] = 'walk' - return cls(*args, **kwargs) + def walk(self) -> "Waypoint": + self.speed = 'walk' + return self + + def set_threshold(self, threshold) -> "Waypoint": + self.threshold = threshold + return self def get_threshold(self, end): """ diff --git a/tasks/map/minimap/minimap.py b/tasks/map/minimap/minimap.py index 7332ff9f5..7c4738006 100644 --- a/tasks/map/minimap/minimap.py +++ b/tasks/map/minimap/minimap.py @@ -46,7 +46,7 @@ class PositionPredictState: class Minimap(MapResource): - def init_position(self, position: tuple[int, int]): + def init_position(self, position: tuple[int | float, int | float]): logger.info(f"init_position:{position}") self.position = position @@ -388,7 +388,7 @@ if __name__ == '__main__': # MapResource.SRCMAP = '../srcmap/srcmap' self = Minimap() # Set plane, assume starting from Jarilo_AdministrativeDistrict - self.set_plane('Jarilo_AdministrativeDistrict', floor='F1') + self.set_plane('Jarilo_BackwaterPass', floor='F1') ui = UI('src') ui.device.disable_stuck_detection()