From 4df1a735a664ef51d8afa7c3d1d479b29aa0f356 Mon Sep 17 00:00:00 2001 From: DoctorReid Date: Sun, 23 Jun 2024 22:05:05 +0800 Subject: [PATCH] =?UTF-8?q?#337=20=E4=BF=AE=E5=A4=8D=E6=A0=A1=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sr/app/calibrator.py | 43 +++++++++++-------------- test/src/test/sr/app/calibrator_test.py | 23 ------------- 2 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 test/src/test/sr/app/calibrator_test.py diff --git a/src/sr/app/calibrator.py b/src/sr/app/calibrator.py index 7b34c75f..336094f4 100644 --- a/src/sr/app/calibrator.py +++ b/src/sr/app/calibrator.py @@ -11,6 +11,7 @@ from sr.const.map_const import TransportPoint from sr.context.context import Context from sr.image.sceenshot import mini_map +from sr.operation import StateOperationNode, OperationOneRoundResult from sr.operation.combine.transport import Transport @@ -22,22 +23,23 @@ class Calibrator(Application): def __init__(self, ctx: Context): super().__init__(ctx, op_name='校准') - def _execute_one_round(self): - self._check_mini_map_pos() - self._check_turning_rate() - # self._check_running_distance() - return True + def add_edges_and_nodes(self) -> None: + """ + 初始化前 添加边和节点 由子类实行 + :return: + """ + nodes = [ + StateOperationNode('传送1', op=Transport(self.ctx, map_const.P01_R02_SP02), wait_after_op=1), + StateOperationNode('小地图定位校准', self.check_mini_map_pos), + StateOperationNode('传送2', op=Transport(self.ctx, map_const.P01_R01_SP03), wait_after_op=1), + StateOperationNode('转向校准', self.check_turning_rate) + ] - def _check_mini_map_pos(self, screenshot: MatLike = None, config=None): - log.info('[小地图定位校准] 开始') - if screenshot is None: - tp: TransportPoint = map_const.P01_R02_SP02 - op = Transport(self.ctx, tp) - if not op.execute().success: - log.error('传送到 %s %s 失败 小地图定位校准 失败', gt(tp.region.cn, 'ocr'), gt(tp.cn, 'ocr')) - return False + self.param_node_list = nodes - screenshot = self.screenshot() + def check_mini_map_pos(self) -> OperationOneRoundResult: + log.info('[小地图定位校准] 开始') + screenshot = self.screenshot() mm_pos: MiniMapPos = mini_map.cal_little_map_pos(screenshot) cfg: GameConfig = self.ctx.game_config cfg.update('mini_map', { @@ -48,23 +50,16 @@ def _check_mini_map_pos(self, screenshot: MatLike = None, config=None): cfg.save() log.info('[小地图定位校准] 完成 位置: (%d, %d) 半径: %d', mm_pos.x, mm_pos.y, mm_pos.r) - return True + return self.round_success(wait=0.5) - def _check_turning_rate(self, tp: bool = True): + def check_turning_rate(self) -> OperationOneRoundResult: """ 检测转向 需要找一个最容易检测到见箭头的位置 通过固定滑动距离 判断转动角度 反推转动角度所需的滑动距离 - :param tp: 是否需要传送 :return: """ log.info('[转向校准] 开始') - if tp: - p: TransportPoint = map_const.P01_R01_SP03 - op = Transport(self.ctx, p) - if not op.execute().success: - log.error('传送到 %s %s 失败 转向校准 失败', gt(p.region.cn), gt(p.cn)) - return False turn_distance = 500 angle = self._get_current_angle() @@ -87,7 +82,7 @@ def _check_turning_rate(self, tp: bool = True): gc.save() log.info('[转向校准] 完成') # cv2.waitKey(0) - return ans + return self.round_success(wait=0.5) def _get_current_angle(self): self.ctx.controller.move('w') diff --git a/test/src/test/sr/app/calibrator_test.py b/test/src/test/sr/app/calibrator_test.py deleted file mode 100644 index 354a9735..00000000 --- a/test/src/test/sr/app/calibrator_test.py +++ /dev/null @@ -1,23 +0,0 @@ -from basic.img.os import get_debug_image -from sr.app.calibrator import Calibrator -from sr.context.context import get_context - - -def _test_check_mini_map_pos(): - screen = get_debug_image('1696613369880') - app._check_mini_map_pos(screen) - - -def _test_check_turning_rate(): - ctx.running = True - ctx.controller.init() - ans = app._check_turning_rate() - -def _test_whole_app(): - app._execute_one_round() - - -if __name__ == '__main__': - ctx = get_context() - app = Calibrator(ctx) - _test_check_turning_rate() \ No newline at end of file