diff --git a/fishy/__main__.py b/fishy/__main__.py index 95289db..04b5351 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -8,6 +8,7 @@ import win32gui import fishy from fishy import web, helper, gui +from fishy.engine.event_handler import EngineEventHandler from fishy.gui import GUI from fishy.helper import Config from fishy.engine import SemiFisherEngine @@ -53,7 +54,7 @@ def main(): if not gui.check_eula(c): return - bot = SemiFisherEngine(c, lambda: gui_window) + bot = EngineEventHandler(c, lambda: gui_window) gui_window = GUI(c, lambda: bot) gui_window.start() diff --git a/fishy/engine/IEngine.py b/fishy/engine/IEngine.py new file mode 100644 index 0000000..5e0f9ca --- /dev/null +++ b/fishy/engine/IEngine.py @@ -0,0 +1,31 @@ +import typing +from abc import ABC, abstractmethod +from threading import Thread +from typing import Callable + +if typing.TYPE_CHECKING: + from fishy.gui import GUI + + +class IEngine(ABC): + + def __init__(self, config, gui_ref: 'Callable[[], GUI]'): + self.get_gui = gui_ref + self.start = False + self.fishPixWindow = None + self.thread = None + self.config = config + + @property + def gui(self): + return self.get_gui().funcs + + def toggle_start(self): + self.start = not self.start + if self.start: + self.thread = Thread(target=self.run) + self.thread.start() + + @abstractmethod + def run(self): + ... diff --git a/fishy/engine/__init__.py b/fishy/engine/__init__.py index a45b0bf..156a158 100644 --- a/fishy/engine/__init__.py +++ b/fishy/engine/__init__.py @@ -1,2 +1 @@ -from fishy.engine.semifisher.funcs import SemiFisherFuncs from fishy.engine.semifisher.engine import SemiFisherEngine diff --git a/fishy/engine/event_handler.py b/fishy/engine/event_handler.py new file mode 100644 index 0000000..7c7f0f5 --- /dev/null +++ b/fishy/engine/event_handler.py @@ -0,0 +1,40 @@ +import logging +from fishy.engine import SemiFisherEngine +from fishy.engine.fullautofisher.engine import FullAuto + + +class EngineEventHandler: + def __init__(self, config, gui_ref): + self.event_handler_running = True + self.event = [] + + self.semi_fisher_engine = SemiFisherEngine(config, gui_ref) + self.full_fisher_engine = FullAuto(config, gui_ref) + + def start_event_handler(self): + while self.event_handler_running: + while len(self.event) > 0: + event = self.event.pop(0) + event() + + def toggle_semifisher(self): + self.event.append(self.semi_fisher_engine.toggle_start) + + def toggle_fullfisher(self): + self.event.append(self.full_fisher_engine.toggle_start) + + def check_pixel_val(self): + def func(): + if self.semi_fisher_engine.start: + self.semi_fisher_engine.show_pixel_vals() + else: + logging.debug("Start the engine first before running this command") + + self.event.append(func) + + def quit(self): + def func(): + self.semi_fisher_engine.start = False + self.event_handler_running = False + + self.event.append(func) diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py new file mode 100644 index 0000000..a93eccf --- /dev/null +++ b/fishy/engine/fullautofisher/engine.py @@ -0,0 +1,13 @@ +import logging +import time + +from fishy.engine.IEngine import IEngine + + +class FullAuto(IEngine): + def run(self): + self.gui.bot_started(True) + while self.start: + logging.debug("running full auto") + time.sleep(0.5) + self.gui.bot_started(False) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 9f28117..4645e4f 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -8,12 +8,12 @@ import logging import pywintypes -from fishy.engine.semifisher.funcs import SemiFisherFuncs +from fishy.engine.IEngine import IEngine from fishy.engine.semifisher import fishing_event from .fishing_event import HookEvent, StickEvent, LookEvent, IdleEvent from .fishing_mode import FishingMode from .pixel_loc import PixelLoc -from .window import Window +from fishy.engine.window import Window if typing.TYPE_CHECKING: from fishy.gui import GUI @@ -23,31 +23,14 @@ def _wait_and_check(gui): time.sleep(10) if not fishing_event._FishingStarted: gui.show_error("Doesn't look like fishing has started\n\n" - "Make sure ProvisionsChalutier addon is visible clearly on top " - "left corner of the screen, either,\n" - "1) Outdated addons are disabled\n" - "2) Other addons are overlapping ProvisionsChalutier\n" - "3) Post processing (re shader) is on\n\n" - "If fixing those doesnt work, try running the bot as admin") + "Check out #faqs on our discord channel to troubleshoot the issue") -class SemiFisherEngine: +class SemiFisherEngine(IEngine): def __init__(self, config, gui_ref: 'Callable[[], GUI]'): - self.funcs = SemiFisherFuncs(self) - self.get_gui = gui_ref + super().__init__(config, gui_ref) - self.start = False - self.fishPixWindow = None - self.fishy_thread = None - self.config = config - self.event_handler_running = True - self.gui_events = [] - - @property - def gui(self): - return self.get_gui().funcs - - def start_fishing(self): + def run(self): """ Starts the fishing code explained in comments in detail @@ -90,13 +73,7 @@ class SemiFisherEngine: logging.info("Fishing engine stopped") self.gui.bot_started(False) - def start_event_handler(self): - while self.event_handler_running: - while len(self.gui_events) > 0: - event = self.gui_events.pop(0) - event() - - def _show_pixel_vals(self): + def show_pixel_vals(self): def show(): freq = 0.5 t = 0 diff --git a/fishy/engine/semifisher/funcs.py b/fishy/engine/semifisher/funcs.py deleted file mode 100644 index 5aaacce..0000000 --- a/fishy/engine/semifisher/funcs.py +++ /dev/null @@ -1,33 +0,0 @@ -import logging -from threading import Thread - - -# noinspection PyProtectedMember -class SemiFisherFuncs: - def __init__(self, engine): - self.engine = engine - - def start_button_pressed(self): - def func(): - self.engine.start = not self.engine.start - if self.engine.start: - self.engine.fishy_thread = Thread(target=self.engine.start_fishing) - self.engine.fishy_thread.start() - - self.engine.gui_events.append(func) - - def check_pixel_val(self): - def func(): - if self.engine.start: - self.engine._show_pixel_vals() - else: - logging.debug("Start the engine first before running this command") - - self.engine.gui_events.append(func) - - def quit(self): - def func(): - self.engine.start = False - self.engine.event_handler_running = False - - self.engine.gui_events.append(func) diff --git a/fishy/engine/semifisher/window.py b/fishy/engine/window.py similarity index 100% rename from fishy/engine/semifisher/window.py rename to fishy/engine/window.py diff --git a/fishy/gui/gui.py b/fishy/gui/gui.py index 5807f37..c779c5f 100644 --- a/fishy/gui/gui.py +++ b/fishy/gui/gui.py @@ -2,6 +2,7 @@ import logging from typing import List, Callable import threading +from fishy.engine.event_handler import EngineEventHandler from fishy.gui.funcs import GUIFuncs from fishy.engine import SemiFisherEngine from . import main_gui @@ -10,7 +11,7 @@ from fishy.helper import Config class GUI: - def __init__(self, config: Config, get_engine: Callable[[], SemiFisherEngine]): + def __init__(self, config: Config, get_engine: Callable[[], EngineEventHandler]): """ :param config: used to get and set configuration settings """ @@ -41,7 +42,7 @@ class GUI: @property def engine(self): - return self.get_engine().funcs + return self.get_engine() def create(self): main_gui._create(self) diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index ab6f111..7a79721 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -24,11 +24,15 @@ def _apply_theme(gui: 'GUI'): def _create(gui: 'GUI'): engines = { - "Semi Fisher": [lambda: config_top.start_semifisher_config(gui), gui.engine.start_button_pressed], - # "Full-Auto Fisher": [not_implemented, not_implemented], + "Semi Fisher": [lambda: config_top.start_semifisher_config(gui), gui.engine.toggle_semifisher], + "Full-Auto Fisher": [not_implemented, gui.engine.toggle_fullfisher], # "Lock Picker": [not_implemented, not_implemented] } + def start_engine(label): + gui._config.set("last_started", label) + engines[label][1]() + gui._root = ThemedTk(theme="equilux", background=True) gui._root.title("Fishybot for Elder Scrolls Online") @@ -88,14 +92,15 @@ def _create(gui: 'GUI'): engine_var = StringVar(start_frame) labels = list(engines.keys()) - engine_select = OptionMenu(start_frame, engine_var, labels[0], *labels) + last_started = gui._config.get("last_started", labels[0]) + engine_select = OptionMenu(start_frame, engine_var, last_started, *labels) engine_select.pack(side=LEFT) - button = Button(start_frame, text="⚙", width=0, command=lambda: engines[engine_var.get()][0]()) - button.pack(side=RIGHT) + config_button = Button(start_frame, text="⚙", width=0, command=lambda: engines[engine_var.get()][0]()) + config_button.pack(side=RIGHT) gui._start_button = Button(start_frame, text="STOP" if gui._bot_running else "START", width=25, - command=lambda: engines[engine_var.get()][1]()) + command=lambda: start_engine(engine_var.get())) gui._start_button.pack(side=RIGHT) start_frame.pack(padx=(10, 10), pady=(5, 15), fill=X)