From 53122ff149730ce5ae3d2da22e91cf369db86c01 Mon Sep 17 00:00:00 2001 From: Raffson Date: Sat, 22 Jul 2023 23:41:42 +0200 Subject: [PATCH] Allow user-made custom injected weapons setup --- game/dcs/aircrafttype.py | 11 +++++++++++ game/persistency.py | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/game/dcs/aircrafttype.py b/game/dcs/aircrafttype.py index aa14aa43..806bb0f8 100644 --- a/game/dcs/aircrafttype.py +++ b/game/dcs/aircrafttype.py @@ -17,6 +17,7 @@ from dcs.weapons_data import weapon_ids from game.data.units import UnitClass from game.dcs.unitproperty import UnitProperty from game.dcs.unittype import UnitType +from game.persistency import user_custom_weapon_injections_dir from game.radio.channels import ( ApacheChannelNamer, ChannelNamer, @@ -465,6 +466,7 @@ class AircraftType(UnitType[Type[FlyingType]]): task_priorities[FlightType.SEAD_SWEEP] = task_priorities[FlightType.SEAD] cls._custom_weapon_injections(aircraft, data) + cls._user_weapon_injections(aircraft) for variant in data.get("variants", [aircraft.id]): yield AircraftType( @@ -522,5 +524,14 @@ class AircraftType(UnitType[Type[FlyingType]]): ][0] setattr(pylon, w, (pylon_number, weapon)) + @staticmethod + def _user_weapon_injections(aircraft): + data_path = user_custom_weapon_injections_dir() / f"{aircraft.id}.yaml" + if not data_path.exists(): + return + with data_path.open(encoding="utf-8") as data_file: + data = yaml.safe_load(data_file) + AircraftType._custom_weapon_injections(aircraft, data) + def __hash__(self) -> int: return hash(self.name) diff --git a/game/persistency.py b/game/persistency.py index f24ec7a1..46cb35d4 100644 --- a/game/persistency.py +++ b/game/persistency.py @@ -87,6 +87,10 @@ def payloads_dir(backup: bool = False) -> Path: return payloads +def user_custom_weapon_injections_dir() -> Path: + return base_path() / "Retribution" / "WeaponInjections" + + def save_dir() -> Path: return base_path() / "Retribution" / "Saves"