mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Support yaml factions
This commit is contained in:
parent
ab32c44b9d
commit
a56aa7a766
@ -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.
|
||||||
|
|||||||
@ -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:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user