2020-10-15 01:26:31 +00:00
|
|
|
import logging
|
2020-10-15 03:19:08 +00:00
|
|
|
import pickle
|
2020-10-15 01:26:31 +00:00
|
|
|
import time
|
2020-10-17 19:45:57 +00:00
|
|
|
from pprint import pprint
|
2020-10-15 01:26:31 +00:00
|
|
|
from tkinter.filedialog import asksaveasfile
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
from fishy.engine.fullautofisher.engine import FullAuto, State
|
2020-10-15 01:26:31 +00:00
|
|
|
|
|
|
|
from fishy.helper import hotkey
|
|
|
|
from fishy.helper.hotkey import Key
|
|
|
|
|
|
|
|
|
|
|
|
class Recorder:
|
|
|
|
recording_fps = 1
|
2020-11-19 13:19:27 +00:00
|
|
|
mark_hole_key = Key.F8
|
2020-10-15 01:26:31 +00:00
|
|
|
|
|
|
|
def __init__(self, engine: FullAuto):
|
|
|
|
self.recording = False
|
|
|
|
self.engine = engine
|
|
|
|
self.timeline = []
|
|
|
|
|
|
|
|
def _mark_hole(self):
|
|
|
|
coods = self.engine.get_coods()
|
|
|
|
self.timeline.append(("check_fish", coods))
|
2020-10-17 22:04:25 +00:00
|
|
|
logging.info("check_fish")
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
def toggle_recording(self):
|
|
|
|
if FullAuto.state != State.RECORDING and FullAuto.state != State.NONE:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.recording = not self.recording
|
|
|
|
if self.recording:
|
|
|
|
self._start_recording()
|
2020-10-15 01:26:31 +00:00
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
def _start_recording(self):
|
|
|
|
FullAuto.state = State.RECORDING
|
2020-11-30 21:04:33 +00:00
|
|
|
logging.info("starting, press f8 to mark hole")
|
2020-11-19 13:19:27 +00:00
|
|
|
hotkey.set_hotkey(Recorder.mark_hole_key, self._mark_hole)
|
2020-10-15 01:26:31 +00:00
|
|
|
|
|
|
|
self.timeline = []
|
|
|
|
|
|
|
|
while self.recording:
|
|
|
|
start_time = time.time()
|
2020-10-15 03:19:08 +00:00
|
|
|
coods = None
|
|
|
|
while not coods:
|
|
|
|
coods = self.engine.get_coods()
|
2020-10-15 01:26:31 +00:00
|
|
|
self.timeline.append(("move_to", (coods[0], coods[1])))
|
|
|
|
|
|
|
|
time_took = time.time() - start_time
|
|
|
|
if time_took <= Recorder.recording_fps:
|
|
|
|
time.sleep(Recorder.recording_fps - time_took)
|
|
|
|
else:
|
|
|
|
logging.warning("Took too much time to record")
|
|
|
|
|
2020-11-19 13:19:27 +00:00
|
|
|
hotkey.free_key(Recorder.mark_hole_key)
|
|
|
|
|
2020-11-30 21:04:33 +00:00
|
|
|
def func():
|
|
|
|
_file = None
|
|
|
|
files = [('Fishy File', '*.fishy')]
|
|
|
|
while not _file:
|
|
|
|
_file = asksaveasfile(mode='wb', filetypes=files, defaultextension=files)
|
|
|
|
|
|
|
|
return _file
|
|
|
|
|
|
|
|
file = self.engine.get_gui().call_in_thread(func, block=True)
|
2020-10-15 01:26:31 +00:00
|
|
|
data = {"full_auto_path": self.timeline}
|
2020-10-17 19:45:57 +00:00
|
|
|
pprint(data)
|
2020-10-15 03:19:08 +00:00
|
|
|
pickle.dump(data, file)
|
2020-10-15 01:26:31 +00:00
|
|
|
file.close()
|
2020-11-19 13:19:27 +00:00
|
|
|
FullAuto.state = State.NONE
|
2020-10-15 01:26:31 +00:00
|
|
|
|