mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +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:
parent
6c7b62b8b1
commit
88d52003b3
@ -244,7 +244,7 @@ class ConflictTheater:
|
||||
raise KeyError(f"Cannot find ControlPoint with ID {id}")
|
||||
|
||||
@staticmethod
|
||||
def from_json(directory: Path, data: Dict[str, Any]) -> ConflictTheater:
|
||||
def from_file_data(directory: Path, data: Dict[str, Any]) -> ConflictTheater:
|
||||
theaters = {
|
||||
"Caucasus": CaucasusTheater,
|
||||
"Nevada": NevadaTheater,
|
||||
|
||||
@ -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}")
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
{
|
||||
"name": "Persian Gulf - Battle of Abu Dhabi",
|
||||
"theater": "Persian Gulf",
|
||||
"authors": "Colonel Panic",
|
||||
"recommended_player_faction": "Iran 2015",
|
||||
"recommended_enemy_faction": "United Arab Emirates 2015",
|
||||
"description": "<p>You have managed to establish a foothold near Ras Al Khaima. Continue pushing south.</p>",
|
||||
"miz": "battle_of_abu_dhabi.miz",
|
||||
"performance": 2,
|
||||
"version": "8.0"
|
||||
}
|
||||
---
|
||||
name: Persian Gulf - Battle of Abu Dhabi
|
||||
theater: Persian Gulf
|
||||
authors: Colonel Panic
|
||||
recommended_player_faction: Iran 2015
|
||||
recommended_enemy_faction: United Arab Emirates 2015
|
||||
description: <p>You have managed to establish a foothold near Ras Al Khaima. Continue pushing south.</p>
|
||||
miz: battle_of_abu_dhabi.miz
|
||||
performance: 2
|
||||
version": "8.0"
|
||||
Loading…
x
Reference in New Issue
Block a user