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"):
|
with logged_duration("Saving game"):
|
||||||
try:
|
try:
|
||||||
with open(_temporary_save_file(), "wb") as f:
|
with open(_temporary_save_file(), "wb") as f:
|
||||||
|
data = _unload_static_data(game)
|
||||||
pickle.dump(game, f)
|
pickle.dump(game, f)
|
||||||
|
_restore_static_data(game, data)
|
||||||
shutil.copy(_temporary_save_file(), game.savepath)
|
shutil.copy(_temporary_save_file(), game.savepath)
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -238,6 +240,18 @@ def save_game(game: Game) -> bool:
|
|||||||
return False
|
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:
|
def autosave(game: Game) -> bool:
|
||||||
"""
|
"""
|
||||||
Autosave to the autosave location
|
Autosave to the autosave location
|
||||||
@ -246,7 +260,9 @@ def autosave(game: Game) -> bool:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(_autosave_path(), "wb") as f:
|
with open(_autosave_path(), "wb") as f:
|
||||||
|
data = _unload_static_data(game)
|
||||||
pickle.dump(game, f)
|
pickle.dump(game, f)
|
||||||
|
_restore_static_data(game, data)
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Could not save game")
|
logging.exception("Could not save game")
|
||||||
|
|||||||
@ -52,10 +52,6 @@ class ConflictTheater:
|
|||||||
self.__dict__ = state
|
self.__dict__ = state
|
||||||
self.landmap = load_landmap(self.landmap_path)
|
self.landmap = load_landmap(self.landmap_path)
|
||||||
|
|
||||||
def __getstate__(self) -> dict[str, Any]:
|
|
||||||
self.landmap = None
|
|
||||||
return self.__dict__
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def landmap_path_for_terrain_name(terrain_name: str) -> Path:
|
def landmap_path_for_terrain_name(terrain_name: str) -> Path:
|
||||||
for theater_dir in THEATER_RESOURCE_DIR.iterdir():
|
for theater_dir in THEATER_RESOURCE_DIR.iterdir():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user