crop is now saved in config, instead of calculating at every launch

- semi auto callbacks are turned on and off by fullauto now
- use pprint to print recorded path data
This commit is contained in:
Adam Saudagar 2020-10-18 01:15:57 +05:30
parent 51560f26d9
commit 421d755a7f
6 changed files with 58 additions and 18 deletions

View File

@ -6,10 +6,11 @@ import time
import numpy as np
import pytesseract
from fishy.engine.semifisher.fishing_mode import FishingMode
from fishy.engine import SemiFisherEngine
from fishy.engine.common.window import WindowClient
from fishy.engine.semifisher import fishing_mode
from fishy.engine.semifisher import fishing_mode, fishing_event
from fishy.engine.common.IEngine import IEngine
from pynput import keyboard, mouse
@ -83,6 +84,7 @@ class FullAuto(IEngine):
self.factors = config.get("full_auto_factors", None)
self._tesseract_dir = None
self._target = None
self.crop = config.get("full_auto_crop")
if self.factors is None:
logging.warning("Please callibrate first")
@ -90,14 +92,21 @@ class FullAuto(IEngine):
self._hole_found_flag = False
self._curr_rotate_y = 0
def update_crop(self):
self.crop = get_crop_coods(self.window)
config.set("full_auto_crop", self.crop)
self.window.crop = self.crop
def run(self):
logging.info("Loading please wait...")
self.initalize_keys()
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
self.window.crop = get_crop_coods(self.window)
self._tesseract_dir = config.get("tesseract_dir", None)
if self.crop is None:
self.update_crop()
self.window.crop = self.crop
self._tesseract_dir = config.get("tesseract_dir", None)
if self._tesseract_dir is None:
logging.warning("Can't start without Tesseract Directory")
self.gui.bot_started(False)
@ -109,6 +118,7 @@ class FullAuto(IEngine):
while self.start:
self.window.show(func=image_pre_process)
cv2.waitKey(25)
self.gui.bot_started(False)
unassign_keys()
logging.info("Quit")
@ -141,7 +151,7 @@ class FullAuto(IEngine):
print("done")
def rotate_to(self, target_angle, from_angle=None):
if target_angle is None:
if from_angle is None:
_, _, from_angle = self.get_coods()
if target_angle < 0:
@ -167,8 +177,11 @@ class FullAuto(IEngine):
def look_for_hole(self):
self._hole_found_flag = False
if FishingMode.CurrentMode == fishing_mode.State.LOOK:
return True
def found_hole(e):
if e == "look":
if e == fishing_mode.State.LOOK:
self._hole_found_flag = True
fishing_mode.subscribers.append(found_hole)
@ -187,6 +200,12 @@ class FullAuto(IEngine):
fishing_mode.subscribers.remove(found_hole)
return self._hole_found_flag
def rotate_back(self):
while self._curr_rotate_y > 0.01:
mse.move(0, -FullAuto.rotate_by)
time.sleep(0.05)
self._curr_rotate_y -= 0.05
def set_target(self):
t = self.get_coods()[:-1]
config.set("target", t)
@ -200,6 +219,8 @@ class FullAuto(IEngine):
hotkey.set_hotkey(Key.F9, lambda: print(self.look_for_hole()))
hotkey.set_hotkey(Key.F10, self.update_crop)
# hotkey.set_hotkey(Key.DOWN, self.set_target)
# hotkey.set_hotkey(Key.RIGHT, lambda: self.move_to(self.config.get("target", None)))
@ -216,5 +237,8 @@ if __name__ == '__main__':
bot = FullAuto(None)
fisher = SemiFisherEngine(None)
hotkey.initalize()
fishing_event.unsubscribe()
fisher.toggle_start()
bot.toggle_start()

View File

@ -1,7 +1,10 @@
import logging
import pickle
from pprint import pprint
from tkinter.filedialog import askopenfile
from fishy.engine.semifisher import fishing_event
from fishy.engine.fullautofisher.engine import FullAuto
from fishy.helper import hotkey, helper
@ -31,13 +34,15 @@ class Player:
self.hole_complete_flag = True
def start_route(self):
file = askopenfile(mode='rb', filetypes=[('Python Files', '*.fishy')])
if not file:
logging.error("file not selected")
return
# file = askopenfile(mode='rb', filetypes=[('Python Files', '*.fishy')])
# if not file:
# logging.error("file not selected")
# return
file = open(r"C:\Users\adam_\Desktop\test3.fishy", 'rb')
data = pickle.load(file)
file.close()
print(data)
pprint(data)
if "full_auto_path" not in data:
logging.error("incorrect file")
return
@ -45,18 +50,21 @@ class Player:
# wait until f8 is pressed
logging.info("press f8 to start")
self.start_moving_flag = False
hotkey.set_hotkey(Key.F8, self._start_moving)
helper.wait_until(lambda: self.start_moving_flag)
logging.info("starting")
for action in self.timeline:
fishing_event.unsubscribe()
if action[0] == "move_to":
self.engine.move_to(action[1])
logging.info("moved")
elif action[0] == "check_fish":
self.engine.move_to(action[1])
self.engine.rotate_to(action[1][2])
fishing_event.subscribe()
# scan for fish hole
logging.info("scanning")
if self.engine.look_for_hole():

View File

@ -1,6 +1,7 @@
import logging
import pickle
import time
from pprint import pprint
from tkinter.filedialog import asksaveasfile
from fishy.engine.fullautofisher.engine import FullAuto
@ -50,7 +51,7 @@ class Recorder:
while not file:
file = asksaveasfile(mode='wb', filetypes=files, defaultextension=files)
data = {"full_auto_path": self.timeline}
print(data)
pprint(data)
pickle.dump(data, file)
file.close()

View File

@ -2,6 +2,7 @@ import time
import typing
from threading import Thread
from typing import Callable
from typing import Optional
import cv2
import logging
@ -20,16 +21,16 @@ if typing.TYPE_CHECKING:
class SemiFisherEngine(IEngine):
def __init__(self, gui_ref: 'Callable[[], GUI]'):
def __init__(self, gui_ref: Optional['Callable[[], GUI]']):
super().__init__(gui_ref)
self.fishPixWindow = None
fishing_event.init()
def run(self):
"""
Starts the fishing
code explained in comments in detail
"""
fishing_event.init()
self.fishPixWindow = WindowClient(color=cv2.COLOR_RGB2HSV)
# check for game window and stuff
@ -51,7 +52,7 @@ class SemiFisherEngine(IEngine):
logging.info("Fishing engine stopped")
self.gui.bot_started(False)
fishing_event.destroy()
fishing_event.unsubscribe()
def _wait_and_check(self):
time.sleep(10)

View File

@ -34,15 +34,20 @@ class FishEvent:
def init():
# todo load config
fishing_mode.subscribers.append(fisher_callback)
subscribe()
FishEvent.action_key = config.get("action_key", 'e')
FishEvent.uid = config.get("uid")
FishEvent.sound = config.get("sound_notification", False)
def destroy():
fishing_mode.subscribers.remove(fisher_callback)
def unsubscribe():
if fisher_callback in fishing_mode.subscribers:
fishing_mode.subscribers.remove(fisher_callback)
def subscribe():
if fisher_callback not in fishing_mode.subscribers:
fishing_mode.subscribers.append(fisher_callback)
def fisher_callback(event: State):

View File

@ -9,6 +9,7 @@ from fishy.helper import helper
class Key(Enum):
F9 = "f9",
F10 = "f10"
F8 = "f8"
F7 = "f7"
UP = "up",