path editing mode done

This commit is contained in:
Adam Saudagar 2021-05-13 17:34:50 +05:30
parent fa02a0895b
commit 41232cc723
2 changed files with 35 additions and 11 deletions

View File

@ -17,7 +17,7 @@ from fishy.helper import helper
from fishy.helper.config import config
def _get_rec_file():
def get_rec_file():
file = config.get("full_auto_rec_file")
if not file:
@ -27,13 +27,23 @@ def _get_rec_file():
file = open(file, 'rb')
data = pickle.load(file)
file.close()
pprint(data)
if "full_auto_path" not in data:
logging.error("invalid file")
return None
return data["full_auto_path"]
def find_nearest(timeline, current):
"""
:param timeline: recording timeline
:param current: current coord
:return: Tuple[index, distance, target_coord]
"""
distances = [(i, math.sqrt((target[0] - current[0]) ** 2 + (target[1] - current[1]) ** 2), target)
for i, (command, target) in enumerate(timeline) if command == "move_to"]
return min(distances, key=lambda d: d[1])
class Player(IMode):
def __init__(self, engine: 'FullAuto'):
self.recording = False
@ -51,18 +61,12 @@ class Player(IMode):
logging.info("player stopped")
def _init(self):
self.timeline = _get_rec_file()
self.timeline = get_rec_file()
if not self.timeline:
log_raise("data not found, can't start")
logging.info("starting player")
self.i = self._closest_point()
def _closest_point(self):
current = self.engine.get_coods()
distances = [(i, math.sqrt((target[0] - current[0]) ** 2 + (target[1] - current[1]) ** 2))
for i, (command, target) in enumerate(self.timeline) if command == "move_to"]
return min(distances, key=lambda d: d[1])[0]
self.i = find_nearest(self.timeline, self.engine.get_coods())[0]
def _loop(self):
action = self.timeline[self.i]

View File

@ -5,15 +5,18 @@ import time
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import askyesno
from typing import List, Optional
import typing
from tkinter.filedialog import asksaveasfile
from fishy.engine.fullautofisher.mode import player
from fishy.helper import helper
from fishy.helper.helper import empty_function
from fishy.helper.popup import PopUp
from playsound import playsound
from fishy import helper
from fishy.helper.config import config
if typing.TYPE_CHECKING:
@ -39,6 +42,14 @@ class Recorder(IMode):
logging.info("check_fish")
def run(self):
old_timeline: Optional[List] = None
start_from = None
if config.get("edit_recorder_mode"):
logging.info("moving to nearest coord in recording")
old_timeline = player.get_rec_file()
start_from = player.find_nearest(old_timeline, self.engine.get_coods())
self.engine.move_to(start_from[2])
logging.info("starting, press LMB to mark hole")
hk = HotKey()
hk.start_process(self._mark_hole)
@ -59,6 +70,15 @@ class Recorder(IMode):
logging.warning("Took too much time to record")
hk.stop()
if config.get("edit_recorder_mode"):
logging.info("moving to nearest coord in recording")
end = player.find_nearest(old_timeline, self.engine.get_coods())
self.engine.move_to(end[2])
part1 = old_timeline[:start_from[0]]
part2 = old_timeline[end[0]:]
self.timeline = part1 + self.timeline + part2
self._ask_to_save()
def _open_save_popup(self):