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:
@@ -53,8 +53,9 @@ class Weapon:
|
||||
def __setstate__(self, state: dict[str, Any]) -> None:
|
||||
# Update any existing models with new data on load.
|
||||
updated = Weapon.with_clsid(state["clsid"])
|
||||
state.update(updated.__dict__)
|
||||
self.__dict__.update(state)
|
||||
if updated is not None:
|
||||
state.update(updated.__dict__)
|
||||
self.__dict__.update(state)
|
||||
|
||||
@classmethod
|
||||
def register(cls, weapon: Weapon) -> None:
|
||||
@@ -67,10 +68,10 @@ class Weapon:
|
||||
cls._by_clsid[weapon.clsid] = weapon
|
||||
|
||||
@classmethod
|
||||
def with_clsid(cls, clsid: str) -> Weapon:
|
||||
def with_clsid(cls, clsid: str) -> Optional[Weapon]:
|
||||
if not cls._loaded:
|
||||
cls._load_all()
|
||||
return cls._by_clsid[clsid]
|
||||
return cls._by_clsid.get(clsid)
|
||||
|
||||
@classmethod
|
||||
def _load_all(cls) -> None:
|
||||
@@ -267,7 +268,9 @@ class Pylon:
|
||||
pylon_number, weapon = value
|
||||
if pylon_number != number:
|
||||
continue
|
||||
allowed.add(Weapon.with_clsid(weapon["clsid"]))
|
||||
allowed_weapon = Weapon.with_clsid(weapon["clsid"])
|
||||
if allowed_weapon is not None:
|
||||
allowed.add(allowed_weapon)
|
||||
|
||||
return cls(number, allowed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user