dcs_liberation/qt_ui/widgets/map/model/threatzonesjs.py
Dan Albert 350f08be2f Add FastAPI interface between the game and map.
A possible explanation for the infrequent CTDs we've been seeing since
adding fast forward is that QWebChannel doesn't keep a reference to the
python objects that it passes to js, so if the object is GC'd before the
front end is done with it, it crashes.

We don't really like QWebChannel anyway, so this begins replacing that
with FastAPI.
2022-02-15 18:14:34 -08:00

57 lines
1.7 KiB
Python

from __future__ import annotations
from PySide2.QtCore import Property, QObject, Signal
from game.server.leaflet import LeafletPoly, ShapelyUtil
from game.theater import ConflictTheater
from game.threatzones import ThreatZones
class ThreatZonesJs(QObject):
fullChanged = Signal()
aircraftChanged = Signal()
airDefensesChanged = Signal()
radarSamsChanged = Signal()
def __init__(
self,
full: list[LeafletPoly],
aircraft: list[LeafletPoly],
air_defenses: list[LeafletPoly],
radar_sams: list[LeafletPoly],
) -> None:
super().__init__()
self._full = full
self._aircraft = aircraft
self._air_defenses = air_defenses
self._radar_sams = radar_sams
@Property(list, notify=fullChanged)
def full(self) -> list[LeafletPoly]:
return self._full
@Property(list, notify=aircraftChanged)
def aircraft(self) -> list[LeafletPoly]:
return self._aircraft
@Property(list, notify=airDefensesChanged)
def airDefenses(self) -> list[LeafletPoly]:
return self._air_defenses
@Property(list, notify=radarSamsChanged)
def radarSams(self) -> list[LeafletPoly]:
return self._radar_sams
@classmethod
def from_zones(cls, zones: ThreatZones, theater: ConflictTheater) -> ThreatZonesJs:
return ThreatZonesJs(
ShapelyUtil.polys_to_leaflet(zones.all, theater),
ShapelyUtil.polys_to_leaflet(zones.airbases, theater),
ShapelyUtil.polys_to_leaflet(zones.air_defenses, theater),
ShapelyUtil.polys_to_leaflet(zones.radar_sam_threats, theater),
)
@classmethod
def empty(cls) -> ThreatZonesJs:
return ThreatZonesJs([], [], [], [])