mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
* Implemented a new option in settings: Default start type for Player flights. * Updated changelog. * Removed unnecessary country parameter. * Restore missing parameter * on_pilot_changed should emit pilots_changed in its finally block, otherwise the start-type isn't updated if you have a single client pilot which you switch to a non-client pilot. Also implemented other changes suggested by @Raffson, such as a more streamlined start_type QComboBox handling and moving the pilots_changed Signal to FlightRosterEditor. * Decouple Signal from QFlighStartType --------- Co-authored-by: Raffson <Raffson@users.noreply.github.com>
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Iterator
|
|
from typing import Optional, TYPE_CHECKING
|
|
|
|
from game.ato.iflightroster import IFlightRoster
|
|
|
|
if TYPE_CHECKING:
|
|
from game.squadrons import Squadron, Pilot
|
|
|
|
|
|
class FlightRoster(IFlightRoster):
|
|
def __init__(self, squadron: Squadron, initial_size: int = 0) -> None:
|
|
self._squadron = squadron
|
|
self.pilots: list[Optional[Pilot]] = []
|
|
self.resize(initial_size)
|
|
|
|
@property
|
|
def squadron(self) -> Squadron:
|
|
return self._squadron
|
|
|
|
def iter_pilots(self) -> Iterator[Pilot | None]:
|
|
yield from self.pilots
|
|
|
|
@property
|
|
def player_count(self) -> int:
|
|
return len([p for p in self.pilots if p is not None and p.player])
|
|
|
|
def pilot_at(self, idx: int) -> Pilot | None:
|
|
return self.pilots[idx]
|
|
|
|
@property
|
|
def max_size(self) -> int:
|
|
return len(self.pilots)
|
|
|
|
def resize(self, new_size: int) -> None:
|
|
if self.max_size > new_size:
|
|
self.squadron.return_pilots(
|
|
[p for p in self.pilots[new_size:] if p is not None]
|
|
)
|
|
self.pilots = self.pilots[:new_size]
|
|
return
|
|
self.pilots.extend(
|
|
[
|
|
self.squadron.claim_available_pilot()
|
|
for _ in range(new_size - self.max_size)
|
|
]
|
|
)
|
|
|
|
def set_pilot(self, index: int, pilot: Optional[Pilot]) -> None:
|
|
if pilot is not None:
|
|
self.squadron.claim_pilot(pilot)
|
|
if (current_pilot := self.pilots[index]) is not None:
|
|
self.squadron.return_pilot(current_pilot)
|
|
self.pilots[index] = pilot
|
|
|
|
def clear(self) -> None:
|
|
self.squadron.return_pilots([p for p in self.pilots if p is not None])
|