dcs-retribution/pydcs_extensions/pylon_injector.py
Raffson 533057a0cc
Introduce pylon ejector for Sufa mod
Will prevent the user having to restart Retribution
2023-07-09 18:21:28 +02:00

34 lines
1.4 KiB
Python

from typing import Tuple, Any
def inject_pylon(to_pylon: Any, from_pylon: Any) -> None:
"""
Inject weapons/ordnance added by mods into the pylons of existing aircraft.
This is done to support mods such as the CJS Super Hornet, which modify aircraft
that exist in stock DCS. Ornance is injected pydcs aircraft classes via introspection
:param to_pylon: The pydcs pylon class of the target aircraft
:param from_pylon: The custom pylon class containing tuples with added weapon info
:return: None
"""
for key, value in from_pylon.__dict__.items():
if key.startswith("__"):
continue
if isinstance(value, Tuple):
setattr(to_pylon, key, value)
def eject_pylon(to_pylon: Any, from_pylon: Any) -> None:
"""
Eject weapons/ordnance added by mods into the pylons of existing aircraft.
This is done to support mods such as the CJS Super Hornet, which modify aircraft
that exist in stock DCS. Ornance is ejected pydcs aircraft classes via introspection
:param to_pylon: The pydcs pylon class of the target aircraft
:param from_pylon: The custom pylon class containing tuples with added weapon info
:return: None
"""
for key, value in from_pylon.__dict__.items():
if key.startswith("__"):
continue
if isinstance(value, Tuple) and hasattr(to_pylon, key):
delattr(to_pylon, key)