diff --git a/src/gui/menu/update.py b/src/gui/menu/update.py index 4219f2af..10e19e34 100644 --- a/src/gui/menu/update.py +++ b/src/gui/menu/update.py @@ -9,23 +9,27 @@ class Update(MenuBarItem): def __init__(self, parent, **kwargs): super().__init__(parent, 'Update', **kwargs) - self.add_command(label='Resources', command=self._resources) + for path in config.bot.submodules: + name = path.capitalize() + self.add_command( + label=name, + command=lambda: UpdatePrompt(self, name, path) + ) - def _resources(self): - ResourcesPrompt(self) - -class ResourcesPrompt(tk.Toplevel): +class UpdatePrompt(tk.Toplevel): RESOLUTION = '500x400' - def __init__(self, parent, **kwargs): + def __init__(self, parent, name, path, **kwargs): super().__init__(parent, **kwargs) + self.path = path + self.grab_set() - self.title('Update Resources') + self.title(f'Update {name}') icon = tk.PhotoImage(file='assets/icon.png') self.iconphoto(False, icon) - self.geometry(ResourcesPrompt.RESOLUTION) + self.geometry(UpdatePrompt.RESOLUTION) self.resizable(False, False) self.columnconfigure(0, weight=1) @@ -72,7 +76,7 @@ def __init__(self, parent, **kwargs): def _update(self, force=False): if force and self.dirty: if not askyesno(title='Overwrite Local Changes', - message='Rebuilding resources will overwrite all local changes. ' + message=f"Rebuilding '{self.path}' will overwrite all local changes. " 'Do you wish to proceed?', icon='warning'): return @@ -82,10 +86,14 @@ def _update(self, force=False): def _refresh_display(self): self.list_var.set(['Searching for local changes...']) self.update() - repo = git.Repo('resources') + repo = git.Repo(self.path) diffs = [] - for item in repo.index.diff(None) + repo.index.diff('HEAD'): - diffs.append(f'{item.change_type} - {item.a_path}') + paths = set() + for item in repo.index.diff(None) + repo.index.diff('HEAD'): # Unstaged and staged changes + path = item.a_path + if path not in paths: # Only show changes once per file, unstaged has precedence over staged + diffs.append(f'{item.change_type} - {path}') + paths.add(path) self.dirty = len(diffs) > 0 if len(diffs) == 0: diffs.append('No local changes found, safe to update') diff --git a/src/modules/bot.py b/src/modules/bot.py index ddf04223..dee47e7c 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -38,7 +38,7 @@ def __init__(self): self.rune_active = False self.rune_pos = (0, 0) self.rune_closest_pos = (0, 0) # Location of the Point closest to rune - self.submodules = {} + self.submodules = [] self.module_name = None self.buff = components.Buff() @@ -230,6 +230,7 @@ def update_submodules(self, force=False): utils.print_separator() print('[~] Retrieving latest submodules:') + self.submodules = [] repo = git.Repo.init() with open('.gitmodules', 'r') as file: lines = file.readlines() @@ -238,7 +239,7 @@ def update_submodules(self, force=False): if lines[i].startswith('[') and i < len(lines) - 2: path = lines[i + 1].split('=')[1].strip() url = lines[i + 2].split('=')[1].strip() - self.submodules[path] = url + self.submodules.append(path) try: repo.git.clone(url, path) # First time loading submodule print(f" - Initialized submodule '{path}'")