Add threat zone support to the new map.

https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
Dan Albert
2022-03-06 19:30:23 -08:00
parent 30aebf2546
commit dc4762a03b
12 changed files with 199 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ from game.server.controlpoints.models import ControlPointJs
from game.server.flights.models import FlightJs
from game.server.frontlines.models import FrontLineJs
from game.server.leaflet import LeafletPoint
from game.server.mapzones.models import ThreatZoneContainerJs
from game.server.supplyroutes.models import SupplyRouteJs
from game.server.tgos.models import TgoJs
@@ -21,6 +22,7 @@ class GameJs(BaseModel):
supply_routes: list[SupplyRouteJs]
front_lines: list[FrontLineJs]
flights: list[FlightJs]
threat_zones: ThreatZoneContainerJs
map_center: LeafletPoint
class Config:
@@ -34,5 +36,6 @@ class GameJs(BaseModel):
supply_routes=SupplyRouteJs.all_in_game(game),
front_lines=FrontLineJs.all_in_game(game),
flights=FlightJs.all_in_game(game, with_waypoints=True),
threat_zones=ThreatZoneContainerJs.for_game(game),
map_center=game.theater.terrain.map_view_default.position.latlng(),
)

View File

@@ -1,11 +1,16 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from pydantic import BaseModel
from game.server.leaflet import LeafletPoint, LeafletPoly, ShapelyUtil
from game.theater import ConflictTheater
from game.threatzones import ThreatZones
if TYPE_CHECKING:
from game import Game
class MapZonesJs(BaseModel):
inclusion: list[LeafletPoly]
@@ -49,3 +54,14 @@ class ThreatZoneContainerJs(BaseModel):
class Config:
title = "ThreatZoneContainer"
@staticmethod
def for_game(game: Game) -> ThreatZoneContainerJs:
return ThreatZoneContainerJs(
blue=ThreatZonesJs.from_zones(
game.threat_zone_for(player=True), game.theater
),
red=ThreatZonesJs.from_zones(
game.threat_zone_for(player=False), game.theater
),
)

View File

@@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
from game import Game
from game.server import GameContext
from .models import MapZonesJs, ThreatZoneContainerJs, ThreatZonesJs, UnculledZoneJs
from .models import MapZonesJs, ThreatZoneContainerJs, UnculledZoneJs
from ..leaflet import ShapelyUtil
router: APIRouter = APIRouter(prefix="/map-zones")
@@ -41,7 +41,4 @@ def get_unculled_zones(
def get_threat_zones(
game: Game = Depends(GameContext.require),
) -> ThreatZoneContainerJs:
return ThreatZoneContainerJs(
blue=ThreatZonesJs.from_zones(game.threat_zone_for(player=True), game.theater),
red=ThreatZonesJs.from_zones(game.threat_zone_for(player=False), game.theater),
)
return ThreatZoneContainerJs.for_game(game)