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

27 lines
856 B
Python

from PySide2.QtCore import Property, QObject, Signal
from game.server.leaflet import LeafletPoly, ShapelyUtil
from game.sim.combat.aircombat import AirCombat
from game.theater import ConflictTheater
class AirCombatJs(QObject):
footprintChanged = Signal()
def __init__(self, combat: AirCombat, theater: ConflictTheater) -> None:
super().__init__()
self.combat = combat
self.theater = theater
self._footprint = self._make_footprint()
@Property(type=list, notify=footprintChanged)
def footprint(self) -> list[LeafletPoly]:
return self._footprint
def refresh(self) -> None:
self._footprint = self._make_footprint()
self.footprintChanged.emit()
def _make_footprint(self) -> list[LeafletPoly]:
return ShapelyUtil.polys_to_leaflet(self.combat.footprint, self.theater)