From cf38113cdeb0249b9e7489de79852b806c40836e Mon Sep 17 00:00:00 2001 From: Raffson Date: Sat, 28 Dec 2024 00:32:32 +0100 Subject: [PATCH] Only remove landmap before saving and immediately restore --- game/persistency.py | 16 ++++++++++++++++ game/theater/conflicttheater.py | 4 ---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/game/persistency.py b/game/persistency.py index ef521329..6b2dad68 100644 --- a/game/persistency.py +++ b/game/persistency.py @@ -230,7 +230,9 @@ def save_game(game: Game) -> bool: with logged_duration("Saving game"): try: with open(_temporary_save_file(), "wb") as f: + data = _unload_static_data(game) pickle.dump(game, f) + _restore_static_data(game, data) shutil.copy(_temporary_save_file(), game.savepath) return True except Exception: @@ -238,6 +240,18 @@ def save_game(game: Game) -> bool: return False +def _restore_static_data(game: Game, data: dict[str, Any]) -> None: + game.theater.landmap = data["landmap"] + + +def _unload_static_data(game: Game) -> dict[str, Any]: + landmap = game.theater.landmap + game.theater.landmap = None + return { + "landmap": landmap, + } + + def autosave(game: Game) -> bool: """ Autosave to the autosave location @@ -246,7 +260,9 @@ def autosave(game: Game) -> bool: """ try: with open(_autosave_path(), "wb") as f: + data = _unload_static_data(game) pickle.dump(game, f) + _restore_static_data(game, data) return True except Exception: logging.exception("Could not save game") diff --git a/game/theater/conflicttheater.py b/game/theater/conflicttheater.py index af4f2daa..b22a1e7f 100644 --- a/game/theater/conflicttheater.py +++ b/game/theater/conflicttheater.py @@ -52,10 +52,6 @@ class ConflictTheater: self.__dict__ = state self.landmap = load_landmap(self.landmap_path) - def __getstate__(self) -> dict[str, Any]: - self.landmap = None - return self.__dict__ - @staticmethod def landmap_path_for_terrain_name(terrain_name: str) -> Path: for theater_dir in THEATER_RESOURCE_DIR.iterdir():