mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Added squadron configuration gui
- added add/remove buttons to Air Wing Menu, implemented remove
This commit is contained in:
21
game/observer.py
Normal file
21
game/observer.py
Normal file
@@ -0,0 +1,21 @@
|
||||
class Event(object):
|
||||
pass
|
||||
|
||||
|
||||
class Observable(object):
|
||||
def __init__(self) -> None:
|
||||
self.callbacks = []
|
||||
|
||||
def subscribe(self, callback) -> None:
|
||||
self.callbacks.append(callback)
|
||||
|
||||
def unsubscribe(self, callback) -> None:
|
||||
self.callbacks.remove(callback)
|
||||
|
||||
def fire(self, **attrs) -> None:
|
||||
e = Event()
|
||||
e.source = self
|
||||
for k, v in attrs.items():
|
||||
setattr(e, k, v)
|
||||
for fn in self.callbacks:
|
||||
fn(e)
|
||||
@@ -9,19 +9,39 @@ from gen.flights.ai_flight_planner_db import aircraft_for_task
|
||||
from gen.flights.closestairfields import ObjectiveDistanceCache
|
||||
from ..theater import ControlPoint, MissionTarget
|
||||
|
||||
from ..observer import Observable
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..ato.flighttype import FlightType
|
||||
from .squadron import Squadron
|
||||
|
||||
|
||||
class AirWing:
|
||||
class AirWing(Observable):
|
||||
def __init__(self, player: bool) -> None:
|
||||
super().__init__()
|
||||
self.player = player
|
||||
self.squadrons: dict[AircraftType, list[Squadron]] = defaultdict(list)
|
||||
|
||||
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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user