Fix save-compat issues

This commit is contained in:
Raffson 2023-05-18 14:37:34 +02:00
parent b14059e134
commit cca45d3729
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 26 additions and 2 deletions

View File

@ -110,6 +110,7 @@ class WeaponType(Enum):
ARM = "ARM"
LGB = "LGB"
TGP = "TGP"
DECOY = "DECOY"
UNKNOWN = "unknown"

View File

@ -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:

View File

@ -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}"