From a3db4705809f155256cfe5803290612493bb621a Mon Sep 17 00:00:00 2001 From: cyberrumor Date: Tue, 10 Oct 2023 22:01:17 -0700 Subject: [PATCH] Make 'all' argument only work on visible components You can now do something like the following: find light # show only lighting mods/plugins deactivate mod all # deactivate all lighting mods find armor # only show armor mods/plugins activate plugin all # activate all armor plugins find # show all components commit # save changes This should help speed up your workflow when working with large amounts of mods/plugins. --- README.md | 4 ++++ ammo/controller.py | 36 ++++++++++++++++++++++++++---- ammo/mod.py | 4 ++++ ammo/ui.py | 55 +++++----------------------------------------- 4 files changed, 46 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 130df8f..af8e10a 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ move mod|plugin Larger numbers win file conflicts. refresh Abandon pending changes. vanilla Disable all managed components and clean up. ``` +Note that the `de/activate mod|plugin` command now supports `all` in place of ``. +This will activate or deactivate all mods or plugins that are visible. Combine this +with the `find` command to quickly organize groups of components with related names. + # Technical Details - AMMO works via creating symlinks in your game directory pointing to your mod files. diff --git a/ammo/controller.py b/ammo/controller.py index 14a92a3..70a1c16 100755 --- a/ammo/controller.py +++ b/ammo/controller.py @@ -767,8 +767,9 @@ def activate(self, mod_or_plugin: Mod | Plugin, index) -> bool: """ if index == "all" and mod_or_plugin in ["mod", "plugin"]: for i in range(len(self.__dict__[f"{mod_or_plugin}s"])): - if self._set_component_state(mod_or_plugin, i, True) is False: - return False + if self.__dict__[f"{mod_or_plugin}s"][i].visible: + if self._set_component_state(mod_or_plugin, i, True) is False: + return False return True return self._set_component_state(mod_or_plugin, index, True) @@ -779,8 +780,9 @@ def deactivate(self, mod_or_plugin: Mod | Plugin, index) -> bool: """ if index == "all" and mod_or_plugin in ["mod", "plugin"]: for i in range(len(self.__dict__[f"{mod_or_plugin}s"])): - if self._set_component_state(mod_or_plugin, i, False) is False: - return False + if self.__dict__[f"{mod_or_plugin}s"][i].visible: + if self._set_component_state(mod_or_plugin, i, False) is False: + return False return True return self._set_component_state(mod_or_plugin, index, False) @@ -953,3 +955,29 @@ def refresh(self) -> bool: """ self.__init__(self.downloads_dir, self.game) return True + + def find(self, *args): + """ + Show only components with any keyword. `find` without args resets. + """ + if not args: + keywords = [] + else: + keywords = args + + for component in self.mods + self.plugins + self.downloads: + component.visible = True + component_keywords = ( + component.name.replace("_", " ").replace("-", " ").lower().split() + ) + + for keyword in keywords: + component.visible = False + if any( + ( + component_keyword.count(keyword.lower()) + for component_keyword in component_keywords + ) + ): + component.visible = True + return True diff --git a/ammo/mod.py b/ammo/mod.py index 05ffc73..10f2968 100755 --- a/ammo/mod.py +++ b/ammo/mod.py @@ -15,6 +15,7 @@ class DLC: name: str enabled: bool = True is_dlc: bool = True + visible: bool = True def __str__(self): return self.name @@ -28,6 +29,7 @@ class Download: name: str location: Path sane: bool = False + visible: bool = True def __post_init__(self): if all(((i.isalnum() or i in [".", "_", "-"]) for i in self.name)): @@ -43,6 +45,7 @@ class Mod: location: Path parent_data_dir: Path + visible: bool = True modconf: None | Path = None has_data_dir: bool = False fomod: bool = False @@ -160,6 +163,7 @@ class Plugin: name: str enabled: bool parent_mod: str + visible: bool = True def __str__(self): return f'{"[True] " if self.enabled else "[False] "}{self.name}' diff --git a/ammo/ui.py b/ammo/ui.py index c1c43df..50d292e 100755 --- a/ammo/ui.py +++ b/ammo/ui.py @@ -8,7 +8,6 @@ class UI: def __init__(self, controller): self.controller = controller - self.keywords = [] # get a map of commands to functions and the amount of args they expect self.command = {} @@ -44,21 +43,12 @@ def __init__(self, controller): } self.command["find"] = { - "func": self.find, + "func": self.controller.find, "args": ["keyword"], "num_args": -1, - "doc": str(self.find.__doc__).strip(), + "doc": str(self.controller.find.__doc__).strip(), } - def find(self, *args): - """ - Show only components with any keyword. `find` without args resets. - """ - if not args: - self.keywords = [] - return True - self.keywords = args - return True def help(self): """ @@ -86,14 +76,12 @@ def help(self): params.append(f"[<{arg}> ...]") else: params.append(f"<{arg}>") - # print(f"{k} {' '.join(params)} {v['doc']}") column_cmd.append(k) column_arg.append(" ".join(params)) column_doc.append(v["doc"]) pad_cmd = max((len(i) for i in column_cmd)) + 1 pad_arg = max((len(i) for i in column_arg)) + 1 - # pad_doc = max([len(i) for i in column_doc]) + 1 for cmd, arg, doc in zip(column_cmd, column_arg, column_doc): print( @@ -119,23 +107,7 @@ def print_status(self): print("---------") for index, download in enumerate(self.controller.downloads): - match = True - download_keywords = ( - download.name.replace("_", " ").replace("-", " ").lower().split() - ) - - for keyword in self.keywords: - match = False - if any( - ( - download_keyword.count(keyword.lower()) - for download_keyword in download_keywords - ) - ): - match = True - break - - if match: + if download.visible: print(f"[{index}] {download}") print() @@ -146,25 +118,10 @@ def print_status(self): print(f" ### | Activated | {'Mod name' if index == 0 else 'Plugin name'}") print("-----|-----------|-----") for priority, component in enumerate(components): - match = True - component_keywords = ( - component.name.replace("_", " ").replace("-", " ").lower().split() - ) - - for keyword in self.keywords: - match = False - if any( - ( - component_keyword.count(keyword.lower()) - for component_keyword in component_keywords - ) - ): - match = True - break - if match: + if component.visible: num = f"[{priority}] " - l = len(str(priority)) + 1 - num = num[0:-l] + length = len(str(priority)) + 1 + num = num[0:-length] print(f"{num} {component}") print()