engines can now run without gui

- corrected logic for look_for_hole, made hotkey start new threads, created mock interface for gui
This commit is contained in:
Adam Saudagar 2020-10-17 13:36:49 +05:30
parent 2edad8110f
commit 825ce11ced
7 changed files with 46 additions and 24 deletions

View File

@ -3,6 +3,8 @@ from abc import ABC, abstractmethod
from threading import Thread
from typing import Callable
from fishy.gui.funcs import GUIFuncs, GUIFuncsMock
if typing.TYPE_CHECKING:
from fishy.gui import GUI
@ -18,6 +20,9 @@ class IEngine(ABC):
@property
def gui(self):
if self.get_gui is None:
return GUIFuncsMock()
return self.get_gui().funcs
def toggle_start(self):

View File

@ -29,9 +29,6 @@ class Calibrate():
def f8_pressed(self):
self._callibrate_state += 1
def start(self):
Thread(target=self.callibrate).start()
def callibrate(self):
logging.debug("Callibrating...")
_callibrate_state = -1

View File

@ -1,4 +1,6 @@
import math
from threading import Thread
import cv2
import logging
import time
@ -7,6 +9,7 @@ import numpy as np
import pywintypes
import pytesseract
from fishy.engine import SemiFisherEngine
from fishy.engine.semifisher import fishing_event
from fishy.engine.IEngine import IEngine
@ -113,8 +116,7 @@ class FullAuto(IEngine):
self.toggle_start()
return
if self.get_gui is not None:
self.gui.bot_started(True)
self.gui.bot_started(True)
while self.start:
Window.loop()
@ -185,11 +187,11 @@ class FullAuto(IEngine):
fishing_event.subscribers.append(found_hole)
t = 0
while not self._hole_found_flag or t <= self.factors[2]/2:
while not self._hole_found_flag and t <= self.factors[2]/2:
mse.move(0, FullAuto.rotate_by)
time.sleep(0.05)
t += 0.05
while not self._hole_found_flag or t > 0:
while not self._hole_found_flag and t > 0:
mse.move(0, -FullAuto.rotate_by)
time.sleep(0.05)
t -= 0.05
@ -198,29 +200,35 @@ class FullAuto(IEngine):
fishing_event.subscribers.remove(found_hole)
return self._hole_found_flag
def set_target(self):
t = self.get_coods()[:-1]
self.config.set("target", t)
print(f"target_coods are {t}")
def initalize_keys(self):
hotkey.set_hotkey(Key.RIGHT, lambda: logging.info(self.get_coods()))
from fishy.engine.fullautofisher.calibrate import Calibrate
hotkey.set_hotkey(Key.UP, Calibrate(self).start)
hotkey.set_hotkey(Key.UP, Calibrate(self).callibrate)
# def down():
# t = self.get_coods()[:-1]
# self.config.set("target", t)
# print(f"target_coods are {t}")
# hotkey.set_hotkey(Key.DOWN, down)
hotkey.set_hotkey(Key.F9, lambda: print(self.look_for_hole()))
# hotkey.set_hotkey(Key.DOWN, self.set_target)
# hotkey.set_hotkey(Key.RIGHT, lambda: self.move_to(self.config.get("target", None)))
from fishy.engine.fullautofisher.recorder import Recorder
from fishy.engine.fullautofisher.player import Player
hotkey.set_hotkey(Key.LEFT, Recorder(self).start)
hotkey.set_hotkey(Key.DOWN, Player(self).start)
hotkey.set_hotkey(Key.LEFT, Recorder(self).start_recording)
hotkey.set_hotkey(Key.DOWN, Player(self).start_route)
logging.info("STARTED")
if __name__ == '__main__':
logging.getLogger("").setLevel(logging.DEBUG)
# noinspection PyTypeChecker
bot = FullAuto(Config(), None)
c = Config()
bot = FullAuto(c, None)
fisher = SemiFisherEngine(c, None)
hotkey.initalize()
# fisher.toggle_start()
bot.toggle_start()

View File

@ -33,9 +33,6 @@ class Player:
if e == "idle":
self.hole_complete_flag = True
def start(self):
Thread(target=self.start_route).start()
def start_route(self):
file = askopenfile(mode='rb', filetypes=[('Python Files', '*.fishy')])
if not file:

View File

@ -26,9 +26,6 @@ class Recorder:
def _stop_recording(self):
self.recording = False
def start(self):
Thread(target=self.start_recording).start()
def start_recording(self):
logging.info("f7 for marking hole, f8 to stop recording")
hotkey.set_hotkey(Key.F7, self._mark_hole)

View File

@ -5,6 +5,23 @@ if typing.TYPE_CHECKING:
from fishy.gui import GUI
class GUIFuncsMock:
def __init__(self):
...
def show_error(self, error):
...
def bot_started(self, started):
...
def quit(self):
...
def start_engine(self):
...
# noinspection PyProtectedMember
class GUIFuncs:
def __init__(self, gui: 'GUI'):

View File

@ -1,4 +1,5 @@
from enum import Enum
from threading import Thread
from typing import Dict, Callable
import keyboard
@ -20,7 +21,7 @@ _hotkeys: Dict[Key, Callable] = {}
def _run_callback(k):
return lambda: _hotkeys[k]()
return lambda: Thread(target=_hotkeys[k]).start()
def initalize():