mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Skip & Log incompatible loadouts
Solution exists in using the 'get' method of the "Weapons dictionary", and subsequentially guarding against None. Aside from that I created a method to validate a payload, which uses this None value to determine validity.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
from collections.abc import Iterable
|
||||
from typing import Iterator, Mapping, Optional, TYPE_CHECKING, Type
|
||||
from typing import Iterator, Mapping, Optional, TYPE_CHECKING, Type, Dict, Any
|
||||
|
||||
from dcs.unittype import FlyingType
|
||||
|
||||
@@ -120,6 +121,10 @@ class Loadout:
|
||||
# }
|
||||
payloads = aircraft.dcs_unit_type.load_payloads()
|
||||
for payload in payloads.values():
|
||||
if not cls.valid_payload(payload["pylons"]):
|
||||
msg = f'Incompatible loadout for {aircraft} skipped: {payload["name"]}'
|
||||
logging.warning(msg)
|
||||
continue
|
||||
name = payload["name"]
|
||||
pylons = payload["pylons"]
|
||||
yield Loadout(
|
||||
@@ -128,6 +133,13 @@ class Loadout:
|
||||
date=None,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def valid_payload(pylons: Dict[int, Dict[str, str]]) -> bool:
|
||||
for p in pylons.values():
|
||||
if Weapon.with_clsid(p["CLSID"]) is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def default_loadout_names_for(cls, task: FlightType) -> Iterator[str]:
|
||||
# This is a list of mappings from the FlightType of a Flight to the type of
|
||||
@@ -189,6 +201,12 @@ class Loadout:
|
||||
dcs_unit_type.load_payloads()
|
||||
payload = dcs_unit_type.loadout_by_name(name)
|
||||
if payload is not None:
|
||||
pylons = {i: {"CLSID": d["clsid"]} for i, d in payload}
|
||||
if not cls.valid_payload(pylons):
|
||||
aircraft = dcs_unit_type.id
|
||||
msg = f"Incompatible loadout for {aircraft} skipped: {name}"
|
||||
logging.warning(msg)
|
||||
continue
|
||||
return Loadout(
|
||||
name,
|
||||
{i: Weapon.with_clsid(d["clsid"]) for i, d in payload},
|
||||
|
||||
Reference in New Issue
Block a user