mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Allow using yaml for campaign definitions.
JSON continues to be supported as well. No additional work needed here, just needed to allow both.
This commit is contained in:
@@ -231,7 +231,7 @@ def create_game(
|
||||
# for loadouts) without saving the generated campaign and reloading it the normal
|
||||
# way.
|
||||
inject_custom_payloads(Path(persistency.base_path()))
|
||||
campaign = Campaign.from_json(campaign_path)
|
||||
campaign = Campaign.from_file(campaign_path)
|
||||
generator = GameGenerator(
|
||||
FACTIONS[blue],
|
||||
FACTIONS[red],
|
||||
|
||||
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
from typing import Any, Dict, List, Union, Tuple
|
||||
|
||||
import packaging.version
|
||||
import yaml
|
||||
from PySide2 import QtGui
|
||||
from PySide2.QtCore import QItemSelectionModel, QModelIndex, Qt
|
||||
from PySide2.QtGui import QStandardItem, QStandardItemModel
|
||||
@@ -41,9 +42,12 @@ class Campaign:
|
||||
path: Path
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, path: Path) -> Campaign:
|
||||
def from_file(cls, path: Path) -> Campaign:
|
||||
with path.open() as campaign_file:
|
||||
data = json.load(campaign_file)
|
||||
if path.suffix == ".yaml":
|
||||
data = yaml.safe_load(campaign_file)
|
||||
else:
|
||||
data = json.load(campaign_file)
|
||||
|
||||
sanitized_theater = data["theater"].replace(" ", "")
|
||||
version_field = data.get("version", "0")
|
||||
@@ -68,7 +72,7 @@ class Campaign:
|
||||
)
|
||||
|
||||
def load_theater(self) -> ConflictTheater:
|
||||
return ConflictTheater.from_json(self.path.parent, self.data)
|
||||
return ConflictTheater.from_file_data(self.path.parent, self.data)
|
||||
|
||||
@property
|
||||
def is_out_of_date(self) -> bool:
|
||||
@@ -105,7 +109,7 @@ def load_campaigns() -> List[Campaign]:
|
||||
for path in campaign_dir.glob("*.json"):
|
||||
try:
|
||||
logging.debug(f"Loading campaign from {path}...")
|
||||
campaign = Campaign.from_json(path)
|
||||
campaign = Campaign.from_file(path)
|
||||
campaigns.append(campaign)
|
||||
except RuntimeError:
|
||||
logging.exception(f"Unable to load campaign from {path}")
|
||||
|
||||
Reference in New Issue
Block a user