mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix mypy issues in faction code.
This commit is contained in:
@@ -2,30 +2,27 @@ from __future__ import annotations
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Type
|
||||
from typing import Dict, Type
|
||||
|
||||
from game.factions.faction import Faction
|
||||
|
||||
FACTION_DIRECTORY = "./resources/factions/"
|
||||
FACTION_DIRECTORY = Path("./resources/factions/")
|
||||
|
||||
|
||||
class FactionLoader:
|
||||
|
||||
@classmethod
|
||||
def load_factions(cls: Type[FactionLoader]) -> {str, Faction}:
|
||||
|
||||
path = Path(FACTION_DIRECTORY)
|
||||
files = [f for f in path.glob("*.json") if f.is_file()]
|
||||
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:
|
||||
logging.info("Loading faction" + str(f))
|
||||
try:
|
||||
with open(f, "r", encoding="utf-8") as fdata:
|
||||
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 as e:
|
||||
logging.error("Unable to load faction : " + path, e)
|
||||
except Exception:
|
||||
logging.exception(f"Unable to load faction : {f}")
|
||||
|
||||
return factions
|
||||
|
||||
Reference in New Issue
Block a user