mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
carrier ops; persistency; ui improvements; refactoring
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
import dcs
|
||||
|
||||
money = 2000
|
||||
aircraft = []
|
||||
armor = []
|
||||
control_points = []
|
||||
|
||||
def add_aircraft(plane: dcs.planes.PlaneType):
|
||||
aircraft.append(plane)
|
||||
|
||||
def add_armor(vehicle: dcs.vehicles.Armor):
|
||||
armor.append(vehicle)
|
||||
|
||||
def add_control_point(cp):
|
||||
control_points.append(cp)
|
||||
@@ -10,3 +10,10 @@ class Debriefing:
|
||||
with open(path, "r") as f:
|
||||
events = json.load(f)
|
||||
|
||||
|
||||
def debriefing_directory_location() -> str:
|
||||
return "build/debrfiefing"
|
||||
|
||||
|
||||
def wait_for_debriefing(callback: typing.Callable):
|
||||
pass
|
||||
|
||||
38
userdata/persistency.py
Normal file
38
userdata/persistency.py
Normal 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
|
||||
Reference in New Issue
Block a user