mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add laser code config parsing and prop generation.
This commit is contained in:
@@ -16,6 +16,7 @@ from dcs.unittype import FlyingType
|
||||
from dcs.weapons_data import weapon_ids
|
||||
|
||||
from game.data.units import UnitClass
|
||||
from game.dcs.lasercodeconfig import LaserCodeConfig
|
||||
from game.dcs.unittype import UnitType
|
||||
from game.persistency import user_custom_weapon_injections_dir
|
||||
from game.radio.channels import (
|
||||
@@ -207,6 +208,7 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
||||
has_built_in_target_pod: bool
|
||||
|
||||
task_priorities: dict[FlightType, int]
|
||||
laser_code_configs: list[LaserCodeConfig]
|
||||
|
||||
_by_name: ClassVar[dict[str, AircraftType]] = {}
|
||||
_by_unit_type: ClassVar[dict[type[FlyingType], list[AircraftType]]] = defaultdict(
|
||||
@@ -501,6 +503,9 @@ class AircraftType(UnitType[Type[FlyingType]]):
|
||||
can_carry_crates=data.get("can_carry_crates", aircraft.helicopter),
|
||||
has_built_in_target_pod=data.get("has_built_in_target_pod", False),
|
||||
task_priorities=task_priorities,
|
||||
laser_code_configs=[
|
||||
LaserCodeConfig.from_yaml(d) for d in data.get("laser_codes", [])
|
||||
],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
48
game/dcs/lasercodeconfig.py
Normal file
48
game/dcs/lasercodeconfig.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
|
||||
|
||||
class LaserCodeConfig(ABC):
|
||||
def __init__(self, pylon: int) -> None:
|
||||
self.pylon = pylon
|
||||
|
||||
@staticmethod
|
||||
def from_yaml(data: dict[str, Any]) -> LaserCodeConfig:
|
||||
pylon = data["pylon"]
|
||||
if (property_def := data.get("property")) is not None:
|
||||
return SinglePropertyLaserCodeConfig(
|
||||
pylon, property_def["id"], int(property_def["digits"])
|
||||
)
|
||||
return MultiplePropertyLaserCodeConfig(
|
||||
pylon, [(d["id"], d["digit"]) for d in data["properties"]]
|
||||
)
|
||||
|
||||
@abstractmethod
|
||||
def property_dict_for_code(self, code: int) -> dict[str, int]:
|
||||
...
|
||||
|
||||
|
||||
class SinglePropertyLaserCodeConfig(LaserCodeConfig):
|
||||
def __init__(self, pylon: int, property_id: str, digits: int) -> None:
|
||||
super().__init__(pylon)
|
||||
self.property_id = property_id
|
||||
self.digits = digits
|
||||
|
||||
def property_dict_for_code(self, code: int) -> dict[str, int]:
|
||||
return {self.property_id: code % 10**self.digits}
|
||||
|
||||
|
||||
class MultiplePropertyLaserCodeConfig(LaserCodeConfig):
|
||||
def __init__(
|
||||
self, pylon: int, property_digit_mappings: list[tuple[str, int]]
|
||||
) -> None:
|
||||
super().__init__(pylon)
|
||||
self.property_digit_mappings = property_digit_mappings
|
||||
|
||||
def property_dict_for_code(self, code: int) -> dict[str, int]:
|
||||
d = {}
|
||||
for prop_id, idx in self.property_digit_mappings:
|
||||
d[prop_id] = code // 10**idx % 10
|
||||
return d
|
||||
Reference in New Issue
Block a user