mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
29 lines
841 B
Python
29 lines
841 B
Python
from __future__ import annotations
|
|
import json
|
|
import logging
|
|
from pathlib import Path
|
|
from typing import Dict, Type
|
|
|
|
from game.factions.faction import Faction
|
|
|
|
FACTION_DIRECTORY = Path("./resources/factions/")
|
|
|
|
|
|
class FactionLoader:
|
|
|
|
@classmethod
|
|
def load_factions(cls: Type[FactionLoader]) -> Dict[str, Faction]:
|
|
files = [f for f in FACTION_DIRECTORY.glob("*.json") if f.is_file()]
|
|
factions = {}
|
|
|
|
for f in files:
|
|
try:
|
|
with f.open("r", encoding="utf-8") as fdata:
|
|
data = json.load(fdata, encoding="utf-8")
|
|
factions[data["name"]] = Faction.from_json(data)
|
|
logging.info("Loaded faction : " + str(f))
|
|
except Exception:
|
|
logging.exception(f"Unable to load faction : {f}")
|
|
|
|
return factions
|