diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index 4cb0b5c..d57cea2 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -1,6 +1,5 @@ import math import traceback -from enum import Enum from threading import Thread import cv2 @@ -8,6 +7,7 @@ import logging import time from fishy.constants import libgps, fishyqr, lam2 +from fishy.engine.fullautofisher.mode.calibrator import Calibrator from fishy.engine.fullautofisher.mode.imode import FullAutoMode from fishy.engine.fullautofisher.mode.player import Player from fishy.engine.fullautofisher.mode.recorder import Recorder @@ -42,7 +42,7 @@ class FullAuto(IEngine): rotate_by = 30 def __init__(self, gui_ref): - from fishy.engine.fullautofisher.calibrator import Calibrator + from fishy.engine.fullautofisher.mode.calibrator import Calibrator from fishy.engine.fullautofisher.test import Test super().__init__(gui_ref) @@ -65,9 +65,15 @@ class FullAuto(IEngine): self.gui.bot_started(True) self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug") - self.mode = Player(self) if FullAutoMode(config.get("full_auto_mode", 0)) == FullAutoMode.Player else Recorder(self) - # todo use config to run player or recorder + self.mode = None + if config.get("calibrate", False): + self.mode = Calibrator(self) + elif FullAutoMode(config.get("full_auto_mode", 0)) == FullAutoMode.Player: + self.mode = Player(self) + elif FullAutoMode(config.get("full_auto_mode", 0)) == FullAutoMode.Recorder: + self.mode = Recorder(self) + # noinspection PyBroadException try: if self.window.get_capture() is None: diff --git a/fishy/engine/fullautofisher/calibrator.py b/fishy/engine/fullautofisher/mode/calibrator.py similarity index 84% rename from fishy/engine/fullautofisher/calibrator.py rename to fishy/engine/fullautofisher/mode/calibrator.py index a660529..a5cefc5 100644 --- a/fishy/engine/fullautofisher/calibrator.py +++ b/fishy/engine/fullautofisher/mode/calibrator.py @@ -4,10 +4,13 @@ import time import cv2 import numpy as np +import typing -from fishy.engine.fullautofisher.engine import FullAuto +if typing.TYPE_CHECKING: + from fishy.engine.fullautofisher.engine import FullAuto from pynput import keyboard, mouse +from fishy.engine.fullautofisher.mode.imode import IMode from fishy.helper.config import config mse = mouse.Controller() @@ -44,8 +47,8 @@ def _get_factor(key): return config.get("full_auto_factors", {}).get(key) -class Calibrator: - def __init__(self, engine: FullAuto): +class Calibrator(IMode): + def __init__(self, engine: 'FullAuto'): self._callibrate_state = -1 self.engine = engine @@ -86,9 +89,11 @@ class Calibrator: move_factor = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) / walking_time _update_factor("move_factor", move_factor) - logging.info("done") + logging.info("walk calibrate done") def _rotate_calibrate(self): + from fishy.engine.fullautofisher.engine import FullAuto + rotate_times = 50 coods = self.engine.get_coods() @@ -110,9 +115,11 @@ class Calibrator: rot_factor = (rot3 - rot2) / rotate_times _update_factor("rot_factor", rot_factor) - logging.info("done") + logging.info("rotate calibrate done") - def calibrate(self): + def run(self): self._walk_calibrate() self._rotate_calibrate() + config.set("calibrate", False) + logging.info("calibration done") diff --git a/fishy/gui/config_top.py b/fishy/gui/config_top.py index 00cb3c6..029f78b 100644 --- a/fishy/gui/config_top.py +++ b/fishy/gui/config_top.py @@ -41,7 +41,9 @@ def start_fullfisher_config(gui: 'GUI'): file_name_label.set(file_name()) def start_calibrate(): - ... + top.quit_top() + config.set("calibrate", True) + gui.engine.toggle_fullfisher() def mode_command(): config.set("full_auto_mode", mode_var.get())