mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Fix error during faction loading
ForceGroup loading failed due to wrong unit parsing and prevented factions without naval units to load before the first faction with naval units got loaded (this affected the Allies 1940 and 44 factions)
This commit is contained in:
parent
d67d32610d
commit
c7270e8654
@ -281,8 +281,15 @@ class ForceGroup:
|
||||
logging.error(f"ForceGroup {name} has no valid tasking")
|
||||
continue
|
||||
|
||||
units = [UnitType.named(unit) for unit in data.get("units")]
|
||||
if not units:
|
||||
units: list[UnitType[Any]] = []
|
||||
for unit in data.get("units"):
|
||||
if GroundUnitType.exists(unit):
|
||||
units.append(GroundUnitType.named(unit))
|
||||
elif ShipUnitType.exists(unit):
|
||||
units.append(ShipUnitType.named(unit))
|
||||
else:
|
||||
logging.error(f"Unit {unit} of ForceGroup {name} is invalid")
|
||||
if len(units) == 0:
|
||||
logging.error(f"ForceGroup {name} has no valid units")
|
||||
continue
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ class UnitType(ABC, Generic[DcsUnitTypeT]):
|
||||
|
||||
@classmethod
|
||||
def named(cls, name: str) -> UnitType[Any]:
|
||||
return cls._by_name[name]
|
||||
raise NotImplementedError
|
||||
|
||||
@classmethod
|
||||
def for_dcs_type(cls, dcs_unit_type: DcsUnitTypeT) -> Iterator[UnitType[Any]]:
|
||||
@ -69,3 +69,13 @@ class UnitType(ABC, Generic[DcsUnitTypeT]):
|
||||
@cached_property
|
||||
def eplrs_capable(self) -> bool:
|
||||
return getattr(self.dcs_unit_type, "eplrs", False)
|
||||
|
||||
@classmethod
|
||||
def exists(cls, name: str) -> bool:
|
||||
if not cls._loaded:
|
||||
cls._load_all()
|
||||
try:
|
||||
cls.named(name)
|
||||
return True
|
||||
except (KeyError, AssertionError):
|
||||
return False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user