Skip to content

Commit

Permalink
Fix reference to undefined variable, code cleanup
Browse files Browse the repository at this point in the history
Fix reference to undefined "visility_conditions", which should have been
"visibility_conditions". Rephrase a few conditions and rename a couple
variables for legibility.
  • Loading branch information
cyberrumor committed Feb 1, 2024
1 parent ba39afa commit 5b3b052
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ammo/fomod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def _get_visible_pages(self) -> list[Page]:
# if there's no condition for visibility, just show it.
if not page.visibility_conditions
# if there's conditions, only include if the conditions are met.
or self._flags_match(page.visility_conditions)
or self._flags_match(page.visibility_conditions)
]

def _get_nodes(self) -> list[ElementTree.Element]:
Expand Down
55 changes: 32 additions & 23 deletions ammo/mod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def __init__(self, downloads_dir: Path, game: Game, *keywords):
continue

name = line.strip().strip("*").strip()

# Don't add duplicate plugins
if name in [p.name for p in self.plugins]:
continue

enabled = self.game.enabled_formula(line)

# Iterate through our mods in reverse so we can assign the conflict
Expand All @@ -161,15 +166,15 @@ def __init__(self, downloads_dir: Path, game: Game, *keywords):
# Only add plugins without mods if the plugin file exists
# and isn't a symlink, because symlinks could be artifacts
# of disabled mods.
if (self.game.data / name).exists() and not (
self.game.data / name
).is_symlink():
plugin = Plugin(
name=name,
mod=mod,
enabled=enabled,
plugin_file = self.game.data / name
if plugin_file.exists() and not plugin_file.is_symlink():
self.plugins.append(
Plugin(
name=name,
mod=mod,
enabled=enabled,
)
)
self.plugins.append(plugin)
continue

if not mod.enabled:
Expand All @@ -178,24 +183,27 @@ def __init__(self, downloads_dir: Path, game: Game, *keywords):
# added automatically when the parent mod is enabled.
continue

plugin_location = self.game.data / name
if not plugin_location.exists() or (
plugin_location.exists() and not plugin_location.resolve().exists()
):
# Disqualify plugins that aren't installed correctly
# from starting as enabled.
plugin_file = self.game.data / name
if not plugin_file.exists():
enabled = False
elif not plugin_file.resolve().exists():
enabled = False
plugin = Plugin(
name=name,
mod=mod,
enabled=enabled,

self.plugins.append(
Plugin(
name=name,
mod=mod,
enabled=enabled,
)
)
if plugin.name not in [p.name for p in self.plugins]:
self.plugins.append(plugin)

# Finish adding DLC from DLCList.txt that was missing from Plugins.txt.
# These will be added as disabled. Since order is preserved in Plugins.txt and
# these were absent from it, their true order can't be preserved.
for plugin in self.dlc:
if plugin.name not in (i.name for i in self.plugins) and plugin.mod is None:
if plugin.mod is None and plugin.name not in (i.name for i in self.plugins):
self.plugins.append(plugin)

downloads: list[Path] = []
Expand Down Expand Up @@ -453,7 +461,7 @@ def configure(self, index: int) -> None:
# files, deactivate this mod and commit changes. This prevents a scenario where
# the user could re-configure a fomod (thereby changing mod.location/Data),
# and quit ammo without running 'commit', which could leave broken symlinks in their
# game.directoryectory.
# game.directory.

mod = self.mods[index]
if not mod.fomod:
Expand All @@ -471,11 +479,12 @@ def configure(self, index: int) -> None:
except FileNotFoundError:
pass

# We need to instantiate a FomodController run it against the UI.
# This will be a new instance of the UI. The old UI will wait for
# this 'configure' function we're in to return.
# We need to instantiate a FomodController and run it against the UI.
# This will be a new instance of the UI.
fomod_controller = FomodController(mod)
ui = UI(fomod_controller)
# ui read/execute/print/loop will break from its loop when the user
# exits or advances past the last page of the fomod config wizard.
ui.repl()

# If we can rebuild the "files" property of the mod, refreshing the controller
Expand Down

0 comments on commit 5b3b052

Please sign in to comment.