Skip to content

Commit

Permalink
Inject mod plane weapons into pydcs.
Browse files Browse the repository at this point in the history
Adds a simple injector that iterates over attrs of an input class and
injects things that look like custom weapons into pydcs's weapons
classes.

Also updated all current mod aircraft configs to perform the injection.
  • Loading branch information
bgreman authored May 26, 2021
1 parent 372bf9d commit c163e2c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pydcs_extensions/a4ec/a4ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dcs.planes import PlaneType
from dcs.weapons_data import Weapons

from pydcs_extensions.weapon_injector import inject_weapons


class WeaponsA4EC:
AN_M57__2__TER_ = {
Expand Down Expand Up @@ -432,6 +434,9 @@ class WeaponsA4EC:
}


inject_weapons(WeaponsA4EC)


class A_4E_C(PlaneType):
id = "A-4E-C"
flyable = True
Expand Down
11 changes: 6 additions & 5 deletions pydcs_extensions/f22a/f22a.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

from dcs import task
from dcs.planes import PlaneType
from dcs.weapons_data import Weapons, weapon_ids
from dcs.weapons_data import Weapons

from pydcs_extensions.weapon_injector import inject_weapons


class F22AWeapons:
AIM_9XX = {"clsid": "{AIM-9XX}", "name": "AIM-9XX", "weight": 85}
AIM_120D = {"clsid": "{AIM-120D}", "name": "AIM-120D", "weight": 152}
Weapons.AIM_9XX = AIM_9XX
Weapons.AIM_120D = AIM_120D
weapon_ids["{AIM-9XX}"] = AIM_9XX
weapon_ids["{AIM-120D}"] = AIM_120D


inject_weapons(F22AWeapons)


class F_22A(PlaneType):
Expand Down
5 changes: 5 additions & 0 deletions pydcs_extensions/hercules/hercules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dcs.planes import PlaneType
from dcs.weapons_data import Weapons

from pydcs_extensions.weapon_injector import inject_weapons


class HerculesWeapons:
GAU_23A_Chain_Gun__30mm_ = {
Expand Down Expand Up @@ -679,6 +681,9 @@ class HerculesWeapons:
}


inject_weapons(HerculesWeapons)


class Hercules(PlaneType):
id = "Hercules"
flyable = True
Expand Down
5 changes: 5 additions & 0 deletions pydcs_extensions/mb339/mb339.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dcs.planes import PlaneType
from dcs.weapons_data import Weapons

from pydcs_extensions.weapon_injector import inject_weapons


class MB_339PAN_Weapons:
ARF8M3_TP = {"clsid": "{ARF8M3_TP}", "name": "ARF8M3 TP", "weight": None}
Expand Down Expand Up @@ -107,6 +109,9 @@ class MB_339PAN_Weapons:
}


inject_weapons(MB_339PAN_Weapons)


class MB_339PAN(PlaneType):
id = "MB-339PAN"
flyable = True
Expand Down
5 changes: 5 additions & 0 deletions pydcs_extensions/su57/su57.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from dcs.planes import PlaneType
from dcs.weapons_data import Weapons

from pydcs_extensions.weapon_injector import inject_weapons


class Su57Weapons:
Kh_59MK2 = {"clsid": "{KH_59MK2}", "name": "Kh-59MK2", "weight": None}
Expand All @@ -18,6 +20,9 @@ class Su57Weapons:
}


inject_weapons(Su57Weapons)


class Su_57(PlaneType):
id = "Su-57"
flyable = True
Expand Down
17 changes: 17 additions & 0 deletions pydcs_extensions/weapon_injector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import List, Any

from dcs.weapons_data import Weapons, weapon_ids


def inject_weapons(weapon_class: Any) -> None:
"""
Inject custom weapons from mods into pydcs weapons databases via introspection
:param weapon_class: The custom weapons class containing dictionaries with weapon info
:return: None
"""
for key, value in weapon_class.__dict__.items():
if key.startswith("__"):
continue
if isinstance(value, dict) and value.get("clsid"):
setattr(Weapons, key, value)
weapon_ids[value["clsid"]] = value

0 comments on commit c163e2c

Please sign in to comment.