diff --git a/resources b/resources index f1f80cf0..c87c40af 160000 --- a/resources +++ b/resources @@ -1 +1 @@ -Subproject commit f1f80cf02bdb95331dc5a9f962dbcd1f5e40d15f +Subproject commit c87c40af1372d2f3a1f80f4d9687527ef28bf57a diff --git a/src/gui/menu/file.py b/src/gui/menu/file.py index 63bdcddb..d0bd77fa 100644 --- a/src/gui/menu/file.py +++ b/src/gui/menu/file.py @@ -1,4 +1,5 @@ import os +import tkinter as tk from src.common import config, utils from src.gui.interfaces import MenuBarItem from tkinter.filedialog import askopenfilename, asksaveasfilename @@ -14,7 +15,14 @@ def __init__(self, parent, **kwargs): self.add_command(label='Save Routine', command=utils.async_callback(self, File._save_routine)) self.add_separator() self.add_command(label='Load Command Book', command=utils.async_callback(self, File._load_commands)) - self.add_command(label='Load Routine', command=utils.async_callback(self, File._load_routine)) + self.add_command( + label='Load Routine', + command=utils.async_callback(self, File._load_routine), + state=tk.DISABLED + ) + + def enable_routine_state(self): + self.entryconfig('Load Routine', state=tk.NORMAL) @staticmethod @utils.run_if_disabled('\n[!] Cannot create a new routine while Auto Maple is enabled') @@ -30,7 +38,7 @@ def _new_routine(): @staticmethod @utils.run_if_disabled('\n[!] Cannot save routines while Auto Maple is enabled') def _save_routine(): - file_path = asksaveasfilename(initialdir=os.path.join(config.RESOURCES_DIR, 'routines'), + file_path = asksaveasfilename(initialdir=get_routines_dir(), title='Save routine', filetypes=[('*.csv', '*.csv')], defaultextension='*.csv') @@ -46,7 +54,7 @@ def _load_routine(): 'Would you like to proceed anyways?', icon='warning'): return - file_path = askopenfilename(initialdir=os.path.join(config.RESOURCES_DIR, 'routines'), + file_path = askopenfilename(initialdir=get_routines_dir(), title='Select a routine', filetypes=[('*.csv', '*.csv')]) if file_path: @@ -66,3 +74,10 @@ def _load_commands(): filetypes=[('*.py', '*.py')]) if file_path: config.bot.load_commands(file_path) + + +def get_routines_dir(): + target = os.path.join(config.RESOURCES_DIR, 'routines', config.bot.module_name) + if not os.path.exists(target): + os.makedirs(target) + return target diff --git a/src/modules/bot.py b/src/modules/bot.py index 6c5432a0..3d8f5e20 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -37,6 +37,7 @@ def __init__(self): self.rune_pos = (0, 0) self.rune_closest_pos = (0, 0) # Location of the Point closest to rune self.submodules = {} + self.module_name = None self.buff = components.Buff() self.command_book = {} @@ -166,7 +167,8 @@ def load_commands(self, file): # Import the desired command book file module_name = splitext(basename(file))[0] - module = __import__(f'resources.command_books.{module_name}', fromlist=['']) + target = '.'.join(['resources', 'command_books', module_name]) + module = __import__(target, fromlist=['']) # Check if the 'step' function has been implemented step_found = False @@ -197,18 +199,20 @@ def load_commands(self, file): new_cb[name] = command if not step_found and not movement_found: - print(f" ! Error: Must either implement both the 'move' and 'adjust' commands, " + print(f" ! Error: Must either implement both 'Move' and 'Adjust' commands, " f"or the function 'step'.") if required_found and (step_found or movement_found): + self.module_name = module_name self.command_book = new_cb self.buff = new_cb['buff']() components.step = new_step + config.gui.menu.file.enable_routine_state() config.gui.view.status.set_cb(basename(file)) config.routine.clear() - print(f"[~] Successfully loaded command book '{module_name}'.") + print(f" ~ Successfully loaded command book '{module_name}'.") return True else: - print(f"[!] Command book '{module_name}' was not loaded.") + print(f" ! Command book '{module_name}' was not loaded.") return False def update_submodules(self, force=False): diff --git a/src/modules/gui.py b/src/modules/gui.py index 1ac99777..87aa727b 100644 --- a/src/modules/gui.py +++ b/src/modules/gui.py @@ -40,6 +40,7 @@ def __init__(self): self.navigation.pack(expand=True, fill='both') self.navigation.bind('<>', self._resize_window) + self.root.focus() def set_routine(self, arr): self.routine_var.set(arr) diff --git a/src/routine/layout.py b/src/routine/layout.py index 8c77a14f..8a62c47c 100644 --- a/src/routine/layout.py +++ b/src/routine/layout.py @@ -64,7 +64,6 @@ def __iter__(self): class Layout: """Uses a quadtree to represent possible player positions in a map layout.""" - LAYOUTS_DIR = os.path.join(config.RESOURCES_DIR, 'layouts') TOLERANCE = settings.move_tolerance / 2 def __init__(self, name): @@ -266,13 +265,13 @@ def load(routine): """ layout_name = splitext(basename(routine))[0] - target = f'{Layout.LAYOUTS_DIR}/{layout_name}' + target = os.path.join(get_layouts_dir(), layout_name) if isfile(target): - print(f" ~ Found existing Layout file at '{target}'.") + print(f" - Found existing Layout file at '{target}'.") with open(target, 'rb') as file: return pickle.load(file) else: - print(f" ~ Created new Layout file at '{target}'.") + print(f" - Created new Layout file at '{target}'.") new_layout = Layout(layout_name) new_layout.save() return new_layout @@ -285,5 +284,12 @@ def save(self): :return: None """ - with open(join(Layout.LAYOUTS_DIR, self.name), 'wb') as file: + layouts_dir = get_layouts_dir() + if not os.path.exists(layouts_dir): + os.makedirs(layouts_dir) + with open(join(layouts_dir, self.name), 'wb') as file: pickle.dump(self, file) + + +def get_layouts_dir(): + return os.path.join(config.RESOURCES_DIR, 'layouts', config.bot.module_name) diff --git a/src/routine/routine.py b/src/routine/routine.py index 9d330f81..fc2232a9 100644 --- a/src/routine/routine.py +++ b/src/routine/routine.py @@ -226,7 +226,7 @@ def load(self, file=None): config.layout = Layout.load(file) config.gui.view.status.set_routine(basename(file)) config.gui.edit.minimap.draw_default() - print(f"[~] Finished loading routine '{basename(splitext(file)[0])}'.") + print(f" ~ Finished loading routine '{basename(splitext(file)[0])}'.") def compile(self, file): self.labels = {}