diff --git a/game/theater/conflicttheater.py b/game/theater/conflicttheater.py index c87d8c77..7f9fee11 100644 --- a/game/theater/conflicttheater.py +++ b/game/theater/conflicttheater.py @@ -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, diff --git a/qt_ui/main.py b/qt_ui/main.py index 70d4dd5b..09cfd011 100644 --- a/qt_ui/main.py +++ b/qt_ui/main.py @@ -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], diff --git a/qt_ui/windows/newgame/QCampaignList.py b/qt_ui/windows/newgame/QCampaignList.py index 1d74e64a..8d2c1fd2 100644 --- a/qt_ui/windows/newgame/QCampaignList.py +++ b/qt_ui/windows/newgame/QCampaignList.py @@ -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}") diff --git a/resources/campaigns/battle_of_abu_dhabi.yaml b/resources/campaigns/battle_of_abu_dhabi.yaml index 5d6c25ca..ebd2d5d4 100644 --- a/resources/campaigns/battle_of_abu_dhabi.yaml +++ b/resources/campaigns/battle_of_abu_dhabi.yaml @@ -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": "
You have managed to establish a foothold near Ras Al Khaima. Continue pushing south.
", - "miz": "battle_of_abu_dhabi.miz", - "performance": 2, - "version": "8.0" -} \ No newline at end of file +--- +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:You have managed to establish a foothold near Ras Al Khaima. Continue pushing south.
+miz: battle_of_abu_dhabi.miz +performance: 2 +version": "8.0" \ No newline at end of file