From cca45d3729fb5bf169e0bd4f1a166d734702936a Mon Sep 17 00:00:00 2001 From: Raffson Date: Thu, 18 May 2023 14:37:34 +0200 Subject: [PATCH] Fix save-compat issues --- game/data/weapons.py | 1 + game/persistency.py | 25 +++++++++++++++++++++++- resources/weapons/standoff/ADM-141A.yaml | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/game/data/weapons.py b/game/data/weapons.py index 46586a01..385cedd2 100644 --- a/game/data/weapons.py +++ b/game/data/weapons.py @@ -110,6 +110,7 @@ class WeaponType(Enum): ARM = "ARM" LGB = "LGB" TGP = "TGP" + DECOY = "DECOY" UNKNOWN = "unknown" diff --git a/game/persistency.py b/game/persistency.py index c42a3f08..d594e898 100644 --- a/game/persistency.py +++ b/game/persistency.py @@ -14,6 +14,29 @@ if TYPE_CHECKING: _dcs_saved_game_folder: Optional[str] = None +# fmt: off +class MigrationUnpickler(pickle.Unpickler): + """Custom unpickler to migrate campaign save-files for when components have been moved""" + def find_class(self, module, name): + if name == "NightMissions": + from game.weather.conditions import NightMissions + return NightMissions + if name == "Conditions": + from game.weather.conditions import Conditions + return Conditions + if name == "ClearSkies": + from game.weather.conditions import ClearSkies + return ClearSkies + if name == "AtmosphericConditions": + from game.weather.atmosphericconditions import AtmosphericConditions + return AtmosphericConditions + if name == "WindConditions": + from game.weather.wind import WindConditions + return WindConditions + return super().find_class(module, name) +# fmt: on + + def setup(user_folder: str) -> None: global _dcs_saved_game_folder _dcs_saved_game_folder = user_folder @@ -50,7 +73,7 @@ def mission_path_for(name: str) -> Path: def load_game(path: str) -> Optional[Game]: with open(path, "rb") as f: try: - save = pickle.load(f) + save = MigrationUnpickler(f).load() save.savepath = path return save except Exception: diff --git a/resources/weapons/standoff/ADM-141A.yaml b/resources/weapons/standoff/ADM-141A.yaml index 6b55a694..2e0c900f 100644 --- a/resources/weapons/standoff/ADM-141A.yaml +++ b/resources/weapons/standoff/ADM-141A.yaml @@ -1,7 +1,7 @@ name: ADM-141A TALD # https://www.designation-systems.net/dusrm/m-141.html year: 1987 -type: decoy +type: DECOY clsids: - "{BRU42_ADM141}" - "{BRU3242_ADM141}"