From 65f42706667499e20c188aaa2dcfc01939fcf65e Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Sun, 29 May 2022 10:36:29 -0700 Subject: [PATCH 1/5] now saving local changes using git stash by default, added rebuild button on top of update button --- src/gui/menu/update.py | 22 ++++++++++++++++------ src/modules/bot.py | 32 +++++++++++++++----------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/gui/menu/update.py b/src/gui/menu/update.py index 1889c101..5312425f 100644 --- a/src/gui/menu/update.py +++ b/src/gui/menu/update.py @@ -52,21 +52,31 @@ def __init__(self, parent, **kwargs): controls_frame.grid(row=0, column=2, sticky=tk.NSEW, padx=10, pady=10) self.refresh = tk.Button(controls_frame, text='Refresh', command=self._refresh_display) self.refresh.pack(side=tk.TOP, pady=(10, 5)) - self.submit = tk.Button(controls_frame, text='Update', command=self._update) - self.submit.pack(side=tk.BOTTOM) + self.soft_update = tk.Button( + controls_frame, + text='Update', + command=self._update + ) + self.soft_update.pack(side=tk.BOTTOM) + self.force_update = tk.Button( + controls_frame, + text='Rebuild', + command=lambda: self._update(force=True) + ) + self.force_update.pack(side=tk.BOTTOM) self.listbox.bindtags((self.listbox, config.gui.root, "all")) # Unbind all events self.bind('', lambda *_: self._refresh_display()) self.focus() - def _update(self): - if self.dirty: + def _update(self, force=False): + if force and self.dirty: if not askyesno(title='Overwrite Local Changes', - message='Updating resources will overwrite local changes. ' + message='Rebuilding resources will overwrite all local changes. ' 'Do you wish to proceed?', icon='warning'): return - config.bot.update_submodules(force=True) + config.bot.update_submodules(force=force) self._close() def _refresh_display(self): diff --git a/src/modules/bot.py b/src/modules/bot.py index f35421e5..4ef59ec6 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -223,10 +223,14 @@ def load_commands(self, file): print(f" ! Command book '{module_name}' was not loaded") def update_submodules(self, force=False): + """ + Pulls updates from the submodule repositories. If FORCE is True, + rebuilds submodules by overwriting all local changes. + """ + utils.print_separator() print('[~] Retrieving latest submodules:') repo = git.Repo.init() - changed = False with open('.gitmodules', 'r') as file: lines = file.readlines() i = 0 @@ -235,26 +239,20 @@ def update_submodules(self, force=False): path = lines[i + 1].split('=')[1].strip() url = lines[i + 2].split('=')[1].strip() self.submodules[path] = url - try: # First time loading submodule - repo.git.clone(url, path) - changed = True + try: + repo.git.clone(url, path) # First time loading submodule print(f" - Initialized submodule '{path}'") except git.exc.GitCommandError: sub_repo = git.Repo(path) - if force: - sub_repo.git.fetch('origin', 'main') - sub_repo.git.reset('--hard', 'FETCH_HEAD') - changed = True - print(f" - Force-updated submodule '{path}'") + if not force: + sub_repo.git.stash() # Save modified content + sub_repo.git.fetch('origin', 'main') + sub_repo.git.reset('--hard', 'FETCH_HEAD') + if not force: + sub_repo.git.checkout('stash', '--', '.') # Restore modified content + print(f" - Updated submodule '{path}'") else: - try: - sub_repo.git.pull('origin', 'main') - changed = True - print(f" - Updated submodule '{path}'") - except git.exc.GitCommandError: - print(f" ! Uncommitted changes in submodule '{path}'") + print(f" - Rebuilt submodule '{path}'") i += 3 else: i += 1 - if not changed: - print(' ~ All submodules are already up to date') From 48288114cc7c9f0d77d2db7d993a0c73606b87f3 Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Sun, 29 May 2022 10:49:05 -0700 Subject: [PATCH 2/5] clear stash after every update/rebuild --- resources | 2 +- src/gui/menu/update.py | 2 +- src/modules/bot.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources b/resources index 4446c283..af45bb34 160000 --- a/resources +++ b/resources @@ -1 +1 @@ -Subproject commit 4446c2836f0c57cebef5cafd287a89dff4e1dd7e +Subproject commit af45bb34da12e672b1a230c0de464461ea42729a diff --git a/src/gui/menu/update.py b/src/gui/menu/update.py index 5312425f..4219f2af 100644 --- a/src/gui/menu/update.py +++ b/src/gui/menu/update.py @@ -63,7 +63,7 @@ def __init__(self, parent, **kwargs): text='Rebuild', command=lambda: self._update(force=True) ) - self.force_update.pack(side=tk.BOTTOM) + self.force_update.pack(side=tk.BOTTOM, pady=(0, 5)) self.listbox.bindtags((self.listbox, config.gui.root, "all")) # Unbind all events self.bind('', lambda *_: self._refresh_display()) diff --git a/src/modules/bot.py b/src/modules/bot.py index 4ef59ec6..52573cd8 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -253,6 +253,7 @@ def update_submodules(self, force=False): print(f" - Updated submodule '{path}'") else: print(f" - Rebuilt submodule '{path}'") + sub_repo.git.stash('clear') i += 3 else: i += 1 From bc563fe76527a8f43baae782475c0ada208a2d5b Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Sun, 29 May 2022 11:02:35 -0700 Subject: [PATCH 3/5] caught error where no changes added to stash, so cannot checkout stash --- src/modules/bot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/bot.py b/src/modules/bot.py index 52573cd8..ddf04223 100644 --- a/src/modules/bot.py +++ b/src/modules/bot.py @@ -249,8 +249,11 @@ def update_submodules(self, force=False): sub_repo.git.fetch('origin', 'main') sub_repo.git.reset('--hard', 'FETCH_HEAD') if not force: - sub_repo.git.checkout('stash', '--', '.') # Restore modified content - print(f" - Updated submodule '{path}'") + try: # Restore modified content + sub_repo.git.checkout('stash', '--', '.') + print(f" - Updated submodule '{path}', restored local changes") + except git.exc.GitCommandError: + print(f" - Updated submodule '{path}'") else: print(f" - Rebuilt submodule '{path}'") sub_repo.git.stash('clear') From 146998dbd0896ff6899c656bf8b6a9b3851a2917 Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Sun, 29 May 2022 11:23:48 -0700 Subject: [PATCH 4/5] generalized update prompt for all future submodules --- src/gui/menu/update.py | 32 ++++++++++++++++++++------------ src/modules/bot.py | 5 +++-- 2 files changed, 23 insertions(+), 14 deletions(-) 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}'") From e3ec7e789ac4fe0cccffaafc49e8dfd6193624c9 Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Sun, 29 May 2022 15:17:30 -0700 Subject: [PATCH 5/5] added all standard US keys to vkeys.py --- src/common/vkeys.py | 72 +++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/common/vkeys.py b/src/common/vkeys.py index 85e8a6ce..c18620a8 100644 --- a/src/common/vkeys.py +++ b/src/common/vkeys.py @@ -24,22 +24,28 @@ # https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN KEY_MAP = { - 'tab': 0x09, # Special Keys + 'left': 0x25, # Arrow keys + 'up': 0x26, + 'right': 0x27, + 'down': 0x28, + + 'backspace': 0x08, # Special keys + 'tab': 0x09, + 'enter': 0x0D, + 'shift': 0x10, + 'ctrl': 0x11, 'alt': 0x12, + 'caps lock': 0x14, + 'esc': 0x1B, 'space': 0x20, - 'shift': 0xA0, - 'ctrl': 0x11, - 'del': 0x2E, - 'end': 0x23, 'page up': 0x21, 'page down': 0x22, + 'end': 0x23, + 'home': 0x24, + 'insert': 0x2D, + 'delete': 0x2E, - 'left': 0x25, # Arrow keys - 'up': 0x26, - 'right': 0x27, - 'down': 0x28, - - '0': 0x30, # Numbers + '0': 0x30, # Numbers '1': 0x31, '2': 0x32, '3': 0x33, @@ -50,20 +56,7 @@ '8': 0x38, '9': 0x39, - 'f1': 0x70, # Function keys - 'f2': 0x71, - 'f3': 0x72, - 'f4': 0x73, - 'f5': 0x74, - 'f6': 0x75, - 'f7': 0x76, - 'f8': 0x77, - 'f9': 0x78, - 'f10': 0x79, - 'f11': 0x7A, - 'f12': 0x7B, - - 'a': 0x41, # Letters + 'a': 0x41, # Letters 'b': 0x42, 'c': 0x43, 'd': 0x44, @@ -88,7 +81,34 @@ 'w': 0x57, 'x': 0x58, 'y': 0x59, - 'z': 0x5A + 'z': 0x5A, + + 'f1': 0x70, # Functional keys + 'f2': 0x71, + 'f3': 0x72, + 'f4': 0x73, + 'f5': 0x74, + 'f6': 0x75, + 'f7': 0x76, + 'f8': 0x77, + 'f9': 0x78, + 'f10': 0x79, + 'f11': 0x7A, + 'f12': 0x7B, + 'num lock': 0x90, + 'scroll lock': 0x91, + + ';': 0xBA, # Special characters + '=': 0xBB, + ',': 0xBC, + '-': 0xBD, + '.': 0xBE, + '/': 0xBF, + '`': 0xC0, + '[': 0xDB, + '\\': 0xDC, + ']': 0xDD, + "'": 0xDE }