Skip to content

Commit

Permalink
Fix Cyberpunk reversed mod priority for archive and redmod
Browse files Browse the repository at this point in the history
  • Loading branch information
ZashIn committed Jan 14, 2024
1 parent ed34be3 commit 7407db2
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions games/game_cyberpunk2077.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def getCreationTime(self) -> QDateTime:
class ModListFile:
list_path: Path
mod_search_pattern: str
reversed_priority: bool = False
"""True: load order priority is reversed compared to MO (first mod has priority)."""


_MOD_TYPE = TypeVar("_MOD_TYPE")
Expand All @@ -209,7 +211,8 @@ def update_modlist(
Args:
mod_type: Which modlist to update.
mod_files (optional): By default mod files in order of mod priority.
mod_files (optional): By default mod files in order of `mod_type` priority
(respecting `self[mod_type].reversed_priority`).
Returns:
`(modlist_path, new_mod_list, old_mod_list)`
Expand Down Expand Up @@ -243,20 +246,27 @@ def absolute_modlist_path(self, mod_type: _MOD_TYPE) -> Path:
return modlist_path

def modfile_names(self, mod_type: _MOD_TYPE) -> Iterable[str]:
"""Get all files from the `mod_type` in load order."""
"""Get all file names from the `mod_type` in MOs load order
(reversed with `self[mod_type].reversed_priority = True`).
"""
yield from (file.name for file in self.modfiles(mod_type))

def modfiles(self, mod_type: _MOD_TYPE) -> Iterable[Path]:
"""Get all files from the `mod_type` in load order."""
"""Get all files from the `mod_type` in MOs load order
(reversed with `self[mod_type].reversed_priority = True`).
"""
mod_search_pattern = self[mod_type].mod_search_pattern
for mod_path in self.active_mod_paths():
for mod_path in self.active_mod_paths(self[mod_type].reversed_priority):
yield from mod_path.glob(mod_search_pattern)

def active_mod_paths(self) -> Iterable[Path]:
"""Yield the path to active mods in load order."""
def active_mod_paths(self, reverse: bool = False) -> Iterable[Path]:
"""Yield the path to active mods in MOs load order."""
mods_path = Path(self._organizer.modsPath())
modlist = self._organizer.modList()
for mod in modlist.allModsByProfilePriority():
mods_load_order = modlist.allModsByProfilePriority()
if reverse:
mods_load_order = reversed(mods_load_order)
for mod in mods_load_order:
if modlist.state(mod) & mobase.ModState.ACTIVE:
yield mods_path / mod

Expand Down Expand Up @@ -320,10 +330,12 @@ def init(self, organizer: mobase.IOrganizer) -> bool:
archive=ModListFile(
Path("archive/pc/mod/modlist.txt"),
"archive/pc/mod/*",
reversed_priority=True,
),
redmod=ModListFile(
Path(self._redmod_deploy_path, "MO_REDmod_load_order.txt"),
"mods/*/",
reversed_priority=True,
),
)
self._rootbuilder_settings = PluginDefaultSettings(
Expand Down

0 comments on commit 7407db2

Please sign in to comment.