Only remove landmap before saving and immediately restore

This commit is contained in:
Raffson 2024-12-28 00:32:32 +01:00
parent 10e7ee7902
commit cf38113cde
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
2 changed files with 16 additions and 4 deletions

View File

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

View File

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