mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Only remove landmap before saving and immediately restore
This commit is contained in:
parent
10e7ee7902
commit
cf38113cde
@ -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")
|
||||
|
||||
@ -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():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user