From 7407db2132f98c50b2a9361346a6ffbf42671b96 Mon Sep 17 00:00:00 2001 From: Zash Date: Sun, 14 Jan 2024 22:17:15 +0100 Subject: [PATCH] Fix Cyberpunk reversed mod priority for archive and redmod --- games/game_cyberpunk2077.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/games/game_cyberpunk2077.py b/games/game_cyberpunk2077.py index c3a499f..4462507 100644 --- a/games/game_cyberpunk2077.py +++ b/games/game_cyberpunk2077.py @@ -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") @@ -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)` @@ -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 @@ -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(