Support yaml factions

This commit is contained in:
Raffson 2024-03-22 21:13:45 +01:00
parent ab32c44b9d
commit a56aa7a766
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
2 changed files with 12 additions and 2 deletions

View File

@ -3,6 +3,7 @@
## Features/Improvements ## Features/Improvements
* **[Payload Editor]** Ability to configure liveries on flight/flight-member level * **[Payload Editor]** Ability to configure liveries on flight/flight-member level
* **[Factions]** Support for definitions in yml/yaml format
## Fixes ## Fixes
* **[UI/UX]** A-10A flights can be edited again. * **[UI/UX]** A-10A flights can be edited again.

View File

@ -5,6 +5,8 @@ import logging
from pathlib import Path from pathlib import Path
from typing import Dict, Iterator, List, Optional, Type from typing import Dict, Iterator, List, Optional, Type
import yaml
from game import persistency from game import persistency
from game.factions.faction import Faction from game.factions.faction import Faction
@ -27,7 +29,11 @@ class FactionLoader:
@staticmethod @staticmethod
def find_faction_files_in(path: Path) -> List[Path]: def find_faction_files_in(path: Path) -> List[Path]:
return [f for f in path.glob("*.json") if f.is_file()] return (
[f for f in path.glob("*.json") if f.is_file()]
+ [f for f in path.glob("*.yaml") if f.is_file()]
+ [f for f in path.glob("*.yml") if f.is_file()]
)
@classmethod @classmethod
def load_factions(cls: Type[FactionLoader]) -> Dict[str, Faction]: def load_factions(cls: Type[FactionLoader]) -> Dict[str, Faction]:
@ -40,7 +46,10 @@ class FactionLoader:
for f in files: for f in files:
try: try:
with f.open("r", encoding="utf-8") as fdata: with f.open("r", encoding="utf-8") as fdata:
data = json.load(fdata) if "yml" in f.name or "yaml" in f.name:
data = yaml.safe_load(fdata)
else:
data = json.load(fdata)
factions[data["name"]] = Faction.from_dict(data) factions[data["name"]] = Faction.from_dict(data)
logging.info("Loaded faction : " + str(f)) logging.info("Loaded faction : " + str(f))
except Exception: except Exception: