mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
This class does far too many things and the file is huge. Split it up into a few more classes.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import random
|
|
from typing import Any, Optional
|
|
|
|
from dcs.unitgroup import FlyingGroup
|
|
|
|
from game import db
|
|
from game.ato import Flight
|
|
|
|
|
|
class AircraftPainter:
|
|
def __init__(self, flight: Flight, group: FlyingGroup[Any]) -> None:
|
|
self.flight = flight
|
|
self.group = group
|
|
|
|
def livery_from_db(self) -> Optional[str]:
|
|
return db.PLANE_LIVERY_OVERRIDES.get(self.flight.unit_type.dcs_unit_type)
|
|
|
|
def livery_from_faction(self) -> Optional[str]:
|
|
faction = self.flight.squadron.coalition.faction
|
|
if (
|
|
choices := faction.liveries_overrides.get(self.flight.unit_type)
|
|
) is not None:
|
|
return random.choice(choices)
|
|
return None
|
|
|
|
def livery_from_squadron(self) -> Optional[str]:
|
|
return self.flight.squadron.livery
|
|
|
|
def determine_livery(self) -> Optional[str]:
|
|
if (livery := self.livery_from_squadron()) is not None:
|
|
return livery
|
|
if (livery := self.livery_from_faction()) is not None:
|
|
return livery
|
|
if (livery := self.livery_from_db()) is not None:
|
|
return livery
|
|
return None
|
|
|
|
def apply_livery(self) -> None:
|
|
livery = self.determine_livery()
|
|
if livery is None:
|
|
return
|
|
for unit in self.group.units:
|
|
unit.livery_id = livery
|