Skip to content

Commit

Permalink
layouts also separated by command book name
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjeffreyz committed May 27, 2022
1 parent 9b2acd3 commit 5ef82cc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/gui/menu/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/modules/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 11 additions & 5 deletions src/routine/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
2 changes: 1 addition & 1 deletion src/routine/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 5ef82cc

Please sign in to comment.