fixed a number of issues: user directory on different drive, carrier ops, multiplayer debriefing parser, multiplayer mission generation; added su25

This commit is contained in:
Vasyl Horbachenko
2018-07-05 02:42:46 +03:00
parent fa55ae1fcc
commit 32fb5ad0e2
8 changed files with 130 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import typing
import re
import threading
import time
import os
@@ -14,7 +15,7 @@ from dcs.unit import UnitType
from game import db
from .persistency import _base_path
from .persistency import base_path
DEBRIEFING_LOG_EXTENSION = "log"
@@ -24,11 +25,53 @@ class Debriefing:
self.destroyed_units = {} # type: typing.Dict[str, typing.Dict[UnitType, int]]
self.alive_units = alive_units # type: typing.Dict[str, typing.Dict[UnitType, int]]
@classmethod
def parse_mp_debrief(cls, string: str):
# TODO: actually write a parser
result = {}
append = False
country = None
unit_type = None
for line in string.split("\n"):
line = line.strip()
if not append:
if line == "world_state =":
append = True
continue
if append:
if line.startswith("country"):
country = re.findall(r"country\s*=\s*(\d+),", line)[0]
if line.startswith("type"):
unit_type = re.findall(r"type\s*=\s*\"(.*?)\",", line)[0]
if country and unit_type:
result[len(result)+1] = {
"country": int(country),
"type": unit_type,
}
country = unit_type = None
if line.strip() == "} -- end of world_state":
break
return {
"debriefing": {
"world_state": result,
},
}
@classmethod
def parse(cls, path: str):
with open(path, "r") as f:
table_string = f.read()
table = parse.loads(table_string)
try:
table = parse.loads(table_string)
except:
table = cls.parse_mp_debrief(table_string)
units = table.get("debriefing", {}).get("world_state", {})
alive_units = {}
@@ -94,7 +137,7 @@ class Debriefing:
def debriefing_directory_location() -> str:
return os.path.join(_base_path(), "liberation_debriefings")
return os.path.join(base_path(), "liberation_debriefings")
def _logfiles_snapshot() -> typing.Dict[str, float]:

View File

@@ -3,9 +3,19 @@ import pickle
import os
import shutil
_user_folder = None # type: str
def _base_path() -> str:
openbeta_path = os.path.expanduser("~\Saved Games\DCS.openbeta")
def setup(user_folder: str):
global _user_folder
_user_folder = user_folder
def base_path() -> str:
global _user_folder
assert _user_folder
openbeta_path = os.path.join(_user_folder, "Saved Games\DCS.openbeta")
if os.path.exists(openbeta_path):
return openbeta_path
else:
@@ -13,11 +23,11 @@ def _base_path() -> str:
def _save_file() -> str:
return os.path.join(_base_path(), "liberation_save")
return os.path.join(base_path(), "liberation_save")
def _temporary_save_file() -> str:
return os.path.join(_base_path(), "liberation_save_tmp")
return os.path.join(base_path(), "liberation_save_tmp")
def _save_file_exists() -> bool:
@@ -25,7 +35,7 @@ def _save_file_exists() -> bool:
def mission_path_for(name: str) -> str:
return os.path.join(_base_path(), "Missions\{}".format(name))
return os.path.join(base_path(), "Missions\{}".format(name))
def restore_game():