mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Finish implementation of add/remove squadrons from AirWingConfigurationDialog
Users can now add and remove squadrons with specific buttons. this also allows new aircraft types to be added as well. - rebased existing PR to develop - reverted observable and changed to signals - changed the general concept so that changes only affect the ui data model and not the game directly. Game will only be updated on apply - removed unused code - adopt to review comments - allow user to choose a predefined squadron preset (also alow none value to use the random generator) - Reuse the squadron defs from the default assigner in the AirWing class - allow user to re-roll the squadron nickname (also added new ui icons for the button)
This commit is contained in:
@@ -7,41 +7,34 @@ from typing import Sequence, Iterator, TYPE_CHECKING, Optional
|
||||
from game.dcs.aircrafttype import AircraftType
|
||||
from gen.flights.ai_flight_planner_db import aircraft_for_task
|
||||
from gen.flights.closestairfields import ObjectiveDistanceCache
|
||||
from .squadrondef import SquadronDef
|
||||
from .squadrondefloader import SquadronDefLoader
|
||||
from ..campaignloader.squadrondefgenerator import SquadronDefGenerator
|
||||
from ..factions.faction import Faction
|
||||
from ..theater import ControlPoint, MissionTarget
|
||||
|
||||
from ..observer import Observable
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game.game import Game
|
||||
from ..ato.flighttype import FlightType
|
||||
from .squadron import Squadron
|
||||
|
||||
|
||||
class AirWing(Observable):
|
||||
def __init__(self, player: bool) -> None:
|
||||
super().__init__()
|
||||
class AirWing:
|
||||
def __init__(self, player: bool, game: Game, faction: Faction) -> None:
|
||||
self.player = player
|
||||
self.squadrons: dict[AircraftType, list[Squadron]] = defaultdict(list)
|
||||
self.squadron_defs = SquadronDefLoader(game, faction).load()
|
||||
self.squadron_def_generator = SquadronDefGenerator(faction)
|
||||
|
||||
def unclaim_squadron_def(self, squadron: Squadron) -> None:
|
||||
if squadron.aircraft in self.squadron_defs:
|
||||
for squadron_def in self.squadron_defs[squadron.aircraft]:
|
||||
if squadron_def.claimed and squadron_def.name == squadron.name:
|
||||
squadron_def.claimed = False
|
||||
|
||||
def add_squadron(self, squadron: Squadron) -> None:
|
||||
new_aircraft_type = squadron.aircraft not in self.squadrons
|
||||
|
||||
self.squadrons[squadron.aircraft].append(squadron)
|
||||
|
||||
if new_aircraft_type:
|
||||
self.fire(type="add_aircraft_type", obj=squadron.aircraft)
|
||||
self.fire(type="add_squadron", obj=squadron)
|
||||
|
||||
def remove_squadron(self, toRemove: Squadron) -> None:
|
||||
if toRemove.aircraft in self.squadrons:
|
||||
self.squadrons[toRemove.aircraft].remove(toRemove)
|
||||
self.fire(type="remove_squadron", obj=toRemove)
|
||||
if len(self.squadrons[toRemove.aircraft]) == 0:
|
||||
self.remove_aircraft_type(toRemove.aircraft)
|
||||
|
||||
def remove_aircraft_type(self, toRemove: AircraftType) -> None:
|
||||
self.squadrons.pop(toRemove)
|
||||
self.fire(type="remove_aircraft_type", obj=toRemove)
|
||||
|
||||
def squadrons_for(self, aircraft: AircraftType) -> Sequence[Squadron]:
|
||||
return self.squadrons[aircraft]
|
||||
|
||||
|
||||
@@ -418,6 +418,7 @@ class Squadron:
|
||||
coalition: Coalition,
|
||||
game: Game,
|
||||
) -> Squadron:
|
||||
squadron_def.claimed = True
|
||||
return Squadron(
|
||||
squadron_def.name,
|
||||
squadron_def.nickname,
|
||||
|
||||
@@ -28,6 +28,7 @@ class SquadronDef:
|
||||
mission_types: tuple[FlightType, ...]
|
||||
operating_bases: OperatingBases
|
||||
pilot_pool: list[Pilot]
|
||||
claimed: bool = False
|
||||
|
||||
auto_assignable_mission_types: set[FlightType] = field(
|
||||
init=False, hash=False, compare=False
|
||||
|
||||
@@ -10,13 +10,13 @@ from .squadrondef import SquadronDef
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
from game.coalition import Coalition
|
||||
from ..factions.faction import Faction
|
||||
|
||||
|
||||
class SquadronDefLoader:
|
||||
def __init__(self, game: Game, coalition: Coalition) -> None:
|
||||
def __init__(self, game: Game, faction: Faction) -> None:
|
||||
self.game = game
|
||||
self.coalition = coalition
|
||||
self.faction = faction
|
||||
|
||||
@staticmethod
|
||||
def squadron_directories() -> Iterator[Path]:
|
||||
@@ -27,8 +27,8 @@ class SquadronDefLoader:
|
||||
|
||||
def load(self) -> dict[AircraftType, list[SquadronDef]]:
|
||||
squadrons: dict[AircraftType, list[SquadronDef]] = defaultdict(list)
|
||||
country = self.coalition.country_name
|
||||
faction = self.coalition.faction
|
||||
country = self.faction.country
|
||||
faction = self.faction
|
||||
any_country = country.startswith("Combined Joint Task Forces ")
|
||||
for directory in self.squadron_directories():
|
||||
for path, squadron_def in self.load_squadrons_from(directory):
|
||||
|
||||
Reference in New Issue
Block a user