carrier ops; persistency; ui improvements; refactoring

This commit is contained in:
Vasyl Horbachenko
2018-06-13 00:15:27 +03:00
parent 3d0babf65f
commit dc303997a6
22 changed files with 348 additions and 368 deletions

38
userdata/persistency.py Normal file
View File

@@ -0,0 +1,38 @@
import pickle
import os
import shutil
from game.game import Game
def _save_file() -> str:
return "build/save"
def _temporary_save_file() -> str:
return "build/save_tmp"
def _save_file_exists() -> bool:
return os.path.exists(_save_file())
def restore_game() -> Game:
if not _save_file_exists():
return None
try:
with open(_save_file(), "rb") as f:
return pickle.load(f)
except:
return None
def save_game(game: Game) -> bool:
try:
with open(_temporary_save_file(), "wb") as f:
pickle.dump(game, f)
shutil.copy(_temporary_save_file(), _save_file())
return True
except:
return False