Skip to content

Commit

Permalink
Merge pull request #105 from tanjeffreyz/dev
Browse files Browse the repository at this point in the history
Improvements to resources + virtual keys
  • Loading branch information
tanjeffreyz authored May 29, 2022
2 parents b2f14a0 + e3ec7e7 commit 9fd3830
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 63 deletions.
2 changes: 1 addition & 1 deletion resources
Submodule resources updated 1 files
+1 −1 README.md
72 changes: 46 additions & 26 deletions src/common/vkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
}


Expand Down
52 changes: 35 additions & 17 deletions src/gui/menu/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -52,30 +56,44 @@ 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, pady=(0, 5))

self.listbox.bindtags((self.listbox, config.gui.root, "all")) # Unbind all events
self.bind('<FocusIn>', 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=f"Rebuilding '{self.path}' 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):
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')
Expand Down
41 changes: 22 additions & 19 deletions src/modules/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -223,38 +223,41 @@ 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:')
self.submodules = []
repo = git.Repo.init()
changed = False
with open('.gitmodules', 'r') as file:
lines = file.readlines()
i = 0
while i < len(lines):
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
try: # First time loading submodule
repo.git.clone(url, path)
changed = True
self.submodules.append(path)
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}'")
else:
try:
sub_repo.git.pull('origin', 'main')
changed = True
print(f" - 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:
try: # Restore modified content
sub_repo.git.checkout('stash', '--', '.')
print(f" - Updated submodule '{path}', restored local changes")
except git.exc.GitCommandError:
print(f" ! Uncommitted changes in submodule '{path}'")
print(f" - Updated submodule '{path}'")
else:
print(f" - Rebuilt submodule '{path}'")
sub_repo.git.stash('clear')
i += 3
else:
i += 1
if not changed:
print(' ~ All submodules are already up to date')

0 comments on commit 9fd3830

Please sign in to comment.