From 5ef82cc0803e2bbe5650a4a26fe1f60550876516 Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Fri, 27 May 2022 14:21:26 -0700 Subject: [PATCH] layouts also separated by command book name --- src/gui/menu/file.py | 1 - src/modules/bot.py | 4 ++-- src/routine/layout.py | 16 +++++++++++----- src/routine/routine.py | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/gui/menu/file.py b/src/gui/menu/file.py index 11ab8556..3ee61788 100644 --- a/src/gui/menu/file.py +++ b/src/gui/menu/file.py @@ -22,7 +22,6 @@ def __init__(self, parent, **kwargs): ) def enable_routine_state(self): - print(config.bot.module_name) self.entryconfig('Load Routine', state=tk.NORMAL) @staticmethod diff --git a/src/modules/bot.py b/src/modules/bot.py index e2080d56..3d8f5e20 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -209,10 +209,10 @@ def load_commands(self, file): 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/routine/layout.py b/src/routine/layout.py index bc717a1e..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', config.bot.module_name) 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 = {}