Skip to content

Commit

Permalink
Make 'all' argument only work on visible components
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cyberrumor committed Oct 11, 2023
1 parent d4c522e commit a3db470
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 53 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ move mod|plugin <from_index> <to_index> 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 `<index>`.
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.
Expand Down
36 changes: 32 additions & 4 deletions ammo/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions ammo/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DLC:
name: str
enabled: bool = True
is_dlc: bool = True
visible: bool = True

def __str__(self):
return self.name
Expand All @@ -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)):
Expand All @@ -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
Expand Down Expand Up @@ -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}'
55 changes: 6 additions & 49 deletions ammo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand All @@ -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()

Expand Down

0 comments on commit a3db470

Please sign in to comment.