mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Move MapZones out of MapModel.
This commit is contained in:
parent
0e6a303c17
commit
2ae820fb20
@ -1,11 +1,12 @@
|
|||||||
from fastapi import Depends, FastAPI
|
from fastapi import Depends, FastAPI
|
||||||
|
|
||||||
from . import debuggeometries, eventstream, flights, navmesh, waypoints
|
from . import debuggeometries, eventstream, flights, mapzones, navmesh, waypoints
|
||||||
from .security import ApiKeyManager
|
from .security import ApiKeyManager
|
||||||
|
|
||||||
app = FastAPI(dependencies=[Depends(ApiKeyManager.verify)])
|
app = FastAPI(dependencies=[Depends(ApiKeyManager.verify)])
|
||||||
app.include_router(debuggeometries.router)
|
app.include_router(debuggeometries.router)
|
||||||
app.include_router(eventstream.router)
|
app.include_router(eventstream.router)
|
||||||
app.include_router(flights.router)
|
app.include_router(flights.router)
|
||||||
|
app.include_router(mapzones.router)
|
||||||
app.include_router(navmesh.router)
|
app.include_router(navmesh.router)
|
||||||
app.include_router(waypoints.router)
|
app.include_router(waypoints.router)
|
||||||
|
|||||||
1
game/server/mapzones/__init__.py
Normal file
1
game/server/mapzones/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .routes import router
|
||||||
11
game/server/mapzones/models.py
Normal file
11
game/server/mapzones/models.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from game.server.leaflet import LeafletPoly
|
||||||
|
|
||||||
|
|
||||||
|
class MapZonesJs(BaseModel):
|
||||||
|
inclusion: list[LeafletPoly]
|
||||||
|
exclusion: list[LeafletPoly]
|
||||||
|
sea: list[LeafletPoly]
|
||||||
21
game/server/mapzones/routes.py
Normal file
21
game/server/mapzones/routes.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
|
||||||
|
from game import Game
|
||||||
|
from game.server import GameContext
|
||||||
|
from .models import MapZonesJs
|
||||||
|
from ..leaflet import ShapelyUtil
|
||||||
|
|
||||||
|
router: APIRouter = APIRouter(prefix="/map-zones")
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/")
|
||||||
|
def get(game: Game = Depends(GameContext.get)) -> MapZonesJs:
|
||||||
|
zones = game.theater.landmap
|
||||||
|
if zones is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
return MapZonesJs(
|
||||||
|
inclusion=ShapelyUtil.polys_to_leaflet(zones.inclusion_zones, game.theater),
|
||||||
|
exclusion=ShapelyUtil.polys_to_leaflet(zones.exclusion_zones, game.theater),
|
||||||
|
sea=ShapelyUtil.polys_to_leaflet(zones.sea_zones, game.theater),
|
||||||
|
)
|
||||||
@ -20,7 +20,6 @@ from .controlpointjs import ControlPointJs
|
|||||||
from .flightjs import FlightJs
|
from .flightjs import FlightJs
|
||||||
from .frontlinejs import FrontLineJs
|
from .frontlinejs import FrontLineJs
|
||||||
from .groundobjectjs import GroundObjectJs
|
from .groundobjectjs import GroundObjectJs
|
||||||
from .mapzonesjs import MapZonesJs
|
|
||||||
from .supplyroutejs import SupplyRouteJs
|
from .supplyroutejs import SupplyRouteJs
|
||||||
from .threatzonecontainerjs import ThreatZoneContainerJs
|
from .threatzonecontainerjs import ThreatZoneContainerJs
|
||||||
from .threatzonesjs import ThreatZonesJs
|
from .threatzonesjs import ThreatZonesJs
|
||||||
@ -54,7 +53,6 @@ class MapModel(QObject):
|
|||||||
flightsChanged = Signal()
|
flightsChanged = Signal()
|
||||||
frontLinesChanged = Signal()
|
frontLinesChanged = Signal()
|
||||||
threatZonesChanged = Signal()
|
threatZonesChanged = Signal()
|
||||||
mapZonesChanged = Signal()
|
|
||||||
unculledZonesChanged = Signal()
|
unculledZonesChanged = Signal()
|
||||||
selectedFlightChanged = Signal(str)
|
selectedFlightChanged = Signal(str)
|
||||||
|
|
||||||
@ -70,7 +68,6 @@ class MapModel(QObject):
|
|||||||
self._threat_zones = ThreatZoneContainerJs(
|
self._threat_zones = ThreatZoneContainerJs(
|
||||||
ThreatZonesJs.empty(), ThreatZonesJs.empty()
|
ThreatZonesJs.empty(), ThreatZonesJs.empty()
|
||||||
)
|
)
|
||||||
self._map_zones = MapZonesJs([], [], [])
|
|
||||||
self._unculled_zones = []
|
self._unculled_zones = []
|
||||||
self._selected_flight_index: Optional[Tuple[int, int]] = None
|
self._selected_flight_index: Optional[Tuple[int, int]] = None
|
||||||
|
|
||||||
@ -99,7 +96,6 @@ class MapModel(QObject):
|
|||||||
self._threat_zones = ThreatZoneContainerJs(
|
self._threat_zones = ThreatZoneContainerJs(
|
||||||
ThreatZonesJs.empty(), ThreatZonesJs.empty()
|
ThreatZonesJs.empty(), ThreatZonesJs.empty()
|
||||||
)
|
)
|
||||||
self._map_zones = MapZonesJs([], [], [])
|
|
||||||
self._unculled_zones = []
|
self._unculled_zones = []
|
||||||
self.cleared.emit()
|
self.cleared.emit()
|
||||||
|
|
||||||
@ -164,7 +160,6 @@ class MapModel(QObject):
|
|||||||
self.reset_atos()
|
self.reset_atos()
|
||||||
self.reset_front_lines()
|
self.reset_front_lines()
|
||||||
self.reset_threat_zones()
|
self.reset_threat_zones()
|
||||||
self.reset_map_zones()
|
|
||||||
self.reset_unculled_zones()
|
self.reset_unculled_zones()
|
||||||
|
|
||||||
def on_game_load(self, game: Optional[Game]) -> None:
|
def on_game_load(self, game: Optional[Game]) -> None:
|
||||||
@ -297,14 +292,6 @@ class MapModel(QObject):
|
|||||||
def threatZones(self) -> ThreatZoneContainerJs:
|
def threatZones(self) -> ThreatZoneContainerJs:
|
||||||
return self._threat_zones
|
return self._threat_zones
|
||||||
|
|
||||||
def reset_map_zones(self) -> None:
|
|
||||||
self._map_zones = MapZonesJs.from_game(self.game)
|
|
||||||
self.mapZonesChanged.emit()
|
|
||||||
|
|
||||||
@Property(MapZonesJs, notify=mapZonesChanged)
|
|
||||||
def mapZones(self) -> MapZonesJs:
|
|
||||||
return self._map_zones
|
|
||||||
|
|
||||||
def on_package_change(self) -> None:
|
def on_package_change(self) -> None:
|
||||||
self.reset_unculled_zones()
|
self.reset_unculled_zones()
|
||||||
|
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from PySide2.QtCore import Property, QObject, Signal
|
|
||||||
|
|
||||||
from game import Game
|
|
||||||
from game.server.leaflet import LeafletPoly, ShapelyUtil
|
|
||||||
|
|
||||||
|
|
||||||
class MapZonesJs(QObject):
|
|
||||||
inclusionZonesChanged = Signal()
|
|
||||||
exclusionZonesChanged = Signal()
|
|
||||||
seaZonesChanged = Signal()
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
inclusion_zones: list[LeafletPoly],
|
|
||||||
exclusion_zones: list[LeafletPoly],
|
|
||||||
sea_zones: list[LeafletPoly],
|
|
||||||
) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self._inclusion_zones = inclusion_zones
|
|
||||||
self._exclusion_zones = exclusion_zones
|
|
||||||
self._sea_zones = sea_zones
|
|
||||||
|
|
||||||
@Property(list, notify=inclusionZonesChanged)
|
|
||||||
def inclusionZones(self) -> list[LeafletPoly]:
|
|
||||||
return self._inclusion_zones
|
|
||||||
|
|
||||||
@Property(list, notify=exclusionZonesChanged)
|
|
||||||
def exclusionZones(self) -> list[LeafletPoly]:
|
|
||||||
return self._exclusion_zones
|
|
||||||
|
|
||||||
@Property(list, notify=seaZonesChanged)
|
|
||||||
def seaZones(self) -> list[LeafletPoly]:
|
|
||||||
return self._sea_zones
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_game(cls, game: Game) -> MapZonesJs:
|
|
||||||
zones = game.theater.landmap
|
|
||||||
return MapZonesJs(
|
|
||||||
ShapelyUtil.polys_to_leaflet(zones.inclusion_zones, game.theater),
|
|
||||||
ShapelyUtil.polys_to_leaflet(zones.exclusion_zones, game.theater),
|
|
||||||
ShapelyUtil.polys_to_leaflet(zones.sea_zones, game.theater),
|
|
||||||
)
|
|
||||||
@ -1124,32 +1124,34 @@ function drawMapZones() {
|
|||||||
inclusionZones.clearLayers();
|
inclusionZones.clearLayers();
|
||||||
exclusionZones.clearLayers();
|
exclusionZones.clearLayers();
|
||||||
|
|
||||||
for (const zone of game.mapZones.seaZones) {
|
getJson("/map-zones").then((zones) => {
|
||||||
L.polygon(zone, {
|
for (const zone of zones.sea) {
|
||||||
color: "#344455",
|
L.polygon(zone, {
|
||||||
fillColor: "#344455",
|
color: "#344455",
|
||||||
fillOpacity: 1,
|
fillColor: "#344455",
|
||||||
interactive: false,
|
fillOpacity: 1,
|
||||||
}).addTo(seaZones);
|
interactive: false,
|
||||||
}
|
}).addTo(seaZones);
|
||||||
|
}
|
||||||
|
|
||||||
for (const zone of game.mapZones.inclusionZones) {
|
for (const zone of zones.inclusion) {
|
||||||
L.polygon(zone, {
|
L.polygon(zone, {
|
||||||
color: "#969696",
|
color: "#969696",
|
||||||
fillColor: "#4b4b4b",
|
fillColor: "#4b4b4b",
|
||||||
fillOpacity: 1,
|
fillOpacity: 1,
|
||||||
interactive: false,
|
interactive: false,
|
||||||
}).addTo(inclusionZones);
|
}).addTo(inclusionZones);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const zone of game.mapZones.exclusionZones) {
|
for (const zone of zones.exclusion) {
|
||||||
L.polygon(zone, {
|
L.polygon(zone, {
|
||||||
color: "#969696",
|
color: "#969696",
|
||||||
fillColor: "#303030",
|
fillColor: "#303030",
|
||||||
fillOpacity: 1,
|
fillOpacity: 1,
|
||||||
interactive: false,
|
interactive: false,
|
||||||
}).addTo(exclusionZones);
|
}).addTo(exclusionZones);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawUnculledZones() {
|
function drawUnculledZones() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user