From 583bb78977b9348482d70648d15f3eaa75b7cfc2 Mon Sep 17 00:00:00 2001 From: Zash Date: Sun, 8 Oct 2023 09:12:14 +0200 Subject: [PATCH] Add BasicLocalSavegames (basic_feature) (#122) * Add `basic_feature.BasicLocalSavegames` (profile specific save games) * Refactor Black & White 2 with BasicLocalSavegames * Refactor Valheim with BasicLocalSavegames * Refactor Vampire Bloodlines with BasicLocalSavegames * Add info about basic local save games to readme --- README.md | 3 ++- basic_features/__init__.py | 8 +++++++- basic_features/basic_local_savegames.py | 21 +++++++++++++++++++++ games/game_blackandwhite2.py | 22 ++-------------------- games/game_valheim.py | 23 ++--------------------- games/game_vampirebloodlines.py | 21 ++------------------- 6 files changed, 36 insertions(+), 62 deletions(-) create mode 100644 basic_features/basic_local_savegames.py diff --git a/README.md b/README.md index be29da2..ee3929a 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,8 @@ The meta-plugin provides some useful extra feature: 2. **Basic save game preview:** If you use the Python version, and if you can easily obtain a picture (file) for any saves, you can provide basic save-game preview by using the `BasicGameSaveGameInfo`. See [games/game_witcher3.py](games/game_witcher3.py) for more details. -3. **Basic mod data checker** (Python): +3. **Basic local save games** (Python): profile specific save games, as in [games/game_valheim.py](games/game_valheim.py). +4. **Basic mod data checker** (Python): Check and fix different mod archive layouts for an automatic installation with the proper file structure, using simple (glob) patterns via `BasicModDataChecker`. See [games/game_valheim.py](games/game_valheim.py) and [game_subnautica.py](games/game_subnautica.py) for an example. diff --git a/basic_features/__init__.py b/basic_features/__init__.py index 64200b5..9326dd9 100644 --- a/basic_features/__init__.py +++ b/basic_features/__init__.py @@ -1,4 +1,10 @@ +from .basic_local_savegames import BasicLocalSavegames from .basic_mod_data_checker import BasicModDataChecker, GlobPatterns from .basic_save_game_info import BasicGameSaveGameInfo -__all__ = ["BasicModDataChecker", "BasicGameSaveGameInfo", "GlobPatterns"] +__all__ = [ + "BasicModDataChecker", + "BasicGameSaveGameInfo", + "GlobPatterns", + "BasicLocalSavegames", +] diff --git a/basic_features/basic_local_savegames.py b/basic_features/basic_local_savegames.py new file mode 100644 index 0000000..6d794ae --- /dev/null +++ b/basic_features/basic_local_savegames.py @@ -0,0 +1,21 @@ +import mobase +from PyQt6.QtCore import QDir + + +class BasicLocalSavegames(mobase.LocalSavegames): + def __init__(self, game_save_dir: QDir): + super().__init__() + self._game_saves_dir = game_save_dir.absolutePath() + + def mappings(self, profile_save_dir: QDir): + return [ + mobase.Mapping( + source=profile_save_dir.absolutePath(), + destination=self._game_saves_dir, + is_directory=True, + create_target=True, + ) + ] + + def prepareProfile(self, profile: mobase.IProfile) -> bool: + return profile.localSavesEnabled() diff --git a/games/game_blackandwhite2.py b/games/game_blackandwhite2.py index d3953d7..a5ff398 100644 --- a/games/game_blackandwhite2.py +++ b/games/game_blackandwhite2.py @@ -11,6 +11,7 @@ from PyQt6.QtCore import QDateTime, QDir, QFile, QFileInfo, Qt from PyQt6.QtGui import QPainter, QPixmap from PyQt6.QtWidgets import QWidget +from ..basic_features import BasicLocalSavegames from ..basic_features.basic_save_game_info import ( BasicGameSaveGame, BasicGameSaveGameInfo, @@ -224,25 +225,6 @@ class BlackAndWhite2SaveGame(BasicGameSaveGame): return self._filepath.parent.parent.name -class BlackAndWhite2LocalSavegames(mobase.LocalSavegames): - def __init__(self, my_game_save_dir: QDir): - super().__init__() - self._savesDir = my_game_save_dir.absolutePath() - - def mappings(self, profile_save_dir: QDir) -> list[mobase.Mapping]: - m = mobase.Mapping() - - m.createTarget = True - m.isDirectory = True - m.source = profile_save_dir.absolutePath() - m.destination = self._savesDir - - return [m] - - def prepareProfile(self, profile: mobase.IProfile): - return profile.localSavesEnabled() - - def _getPreview(savepath: Path): save = BlackAndWhite2SaveGame(savepath) lines = [ @@ -365,7 +347,7 @@ class BlackAndWhite2Game(BasicGame, mobase.IPluginFileMapper): def init(self, organizer: mobase.IOrganizer) -> bool: BasicGame.init(self, organizer) self._featureMap[mobase.ModDataChecker] = BlackAndWhite2ModDataChecker() - self._featureMap[mobase.LocalSavegames] = BlackAndWhite2LocalSavegames( + self._featureMap[mobase.LocalSavegames] = BasicLocalSavegames( self.savesDirectory() ) self._featureMap[mobase.SaveGameInfo] = BlackAndWhite2SaveGameInfo(_getPreview) diff --git a/games/game_valheim.py b/games/game_valheim.py index a7d133a..7ce64f9 100644 --- a/games/game_valheim.py +++ b/games/game_valheim.py @@ -11,7 +11,7 @@ from typing import Any, Optional, TextIO import mobase from PyQt6.QtCore import QDir -from ..basic_features.basic_mod_data_checker import BasicModDataChecker, GlobPatterns +from ..basic_features import BasicLocalSavegames, BasicModDataChecker, GlobPatterns from ..basic_features.basic_save_game_info import BasicGameSaveGame from ..basic_game import BasicGame @@ -286,25 +286,6 @@ class ValheimWorldSaveGame(ValheimSaveGame): return files -class ValheimLocalSavegames(mobase.LocalSavegames): - def __init__(self, my_game_save_dir: QDir): - super().__init__() - self._saves_dir = my_game_save_dir.absolutePath() - - def mappings(self, profile_save_dir: QDir): - return [ - mobase.Mapping( - source=profile_save_dir.absolutePath(), - destination=self._saves_dir, - is_directory=True, - create_target=True, - ) - ] - - def prepareProfile(self, profile: mobase.IProfile): - return profile.localSavesEnabled() - - class ValheimGame(BasicGame): Name = "Valheim Support Plugin" Author = "Zash" @@ -377,7 +358,7 @@ class ValheimGame(BasicGame): }, ) ) - self._featureMap[mobase.LocalSavegames] = ValheimLocalSavegames( + self._featureMap[mobase.LocalSavegames] = BasicLocalSavegames( self.savesDirectory() ) self._overwrite_sync = OverwriteSync(organizer=self._organizer, game=self) diff --git a/games/game_vampirebloodlines.py b/games/game_vampirebloodlines.py index 0beb50f..b5e84ff 100644 --- a/games/game_vampirebloodlines.py +++ b/games/game_vampirebloodlines.py @@ -4,6 +4,7 @@ from typing import List import mobase from PyQt6.QtCore import QDir +from ..basic_features import BasicLocalSavegames from ..basic_game import BasicGame, BasicGameSaveGame @@ -48,24 +49,6 @@ class VampireSaveGame(BasicGameSaveGame): self.elapsedTime = None -class VampireLocalSavegames(mobase.LocalSavegames): - def __init__(self, my_game_save_dir: QDir): - super().__init__() - self._saves_dir = my_game_save_dir.absolutePath() - - def mappings(self, profile_save_dir: QDir): - m = mobase.Mapping() - m.createTarget = True - m.isDirectory = True - m.source = profile_save_dir.absolutePath() - m.destination = self._saves_dir - - return [m] - - def prepareProfile(self, profile: mobase.IProfile): - return profile.localSavesEnabled() - - class VampireTheMasqueradeBloodlinesGame(BasicGame): Name = "Vampire - The Masquerade: Bloodlines Support Plugin" Author = "John" @@ -91,7 +74,7 @@ class VampireTheMasqueradeBloodlinesGame(BasicGame): def init(self, organizer: mobase.IOrganizer) -> bool: super().init(organizer) self._featureMap[mobase.ModDataChecker] = VampireModDataChecker() - self._featureMap[mobase.LocalSavegames] = VampireLocalSavegames( + self._featureMap[mobase.LocalSavegames] = BasicLocalSavegames( self.savesDirectory() ) return True