mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add navmesh support to the new map.
https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
@@ -9,6 +9,7 @@ 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.navmesh.models import NavMeshesJs
|
||||
from game.server.supplyroutes.models import SupplyRouteJs
|
||||
from game.server.tgos.models import TgoJs
|
||||
|
||||
@@ -23,6 +24,7 @@ class GameJs(BaseModel):
|
||||
front_lines: list[FrontLineJs]
|
||||
flights: list[FlightJs]
|
||||
threat_zones: ThreatZoneContainerJs
|
||||
navmeshes: NavMeshesJs
|
||||
map_center: LeafletPoint
|
||||
|
||||
class Config:
|
||||
@@ -37,5 +39,6 @@ class GameJs(BaseModel):
|
||||
front_lines=FrontLineJs.all_in_game(game),
|
||||
flights=FlightJs.all_in_game(game, with_waypoints=True),
|
||||
threat_zones=ThreatZoneContainerJs.for_game(game),
|
||||
navmeshes=NavMeshesJs.from_game(game),
|
||||
map_center=game.theater.terrain.map_view_default.position.latlng(),
|
||||
)
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.server.leaflet import LeafletPoly
|
||||
from game.server.leaflet import LeafletPoly, ShapelyUtil
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
from game.navmesh import NavMesh
|
||||
|
||||
|
||||
class NavMeshPolyJs(BaseModel):
|
||||
@@ -11,3 +17,37 @@ class NavMeshPolyJs(BaseModel):
|
||||
|
||||
class Config:
|
||||
title = "NavMeshPoly"
|
||||
|
||||
|
||||
class NavMeshJs(BaseModel):
|
||||
polys: list[NavMeshPolyJs]
|
||||
|
||||
class Config:
|
||||
title = "NavMesh"
|
||||
|
||||
@staticmethod
|
||||
def from_navmesh(navmesh: NavMesh, game: Game) -> NavMeshJs:
|
||||
return NavMeshJs(
|
||||
polys=[
|
||||
NavMeshPolyJs(
|
||||
poly=ShapelyUtil.poly_to_leaflet(p.poly, game.theater),
|
||||
threatened=p.threatened,
|
||||
)
|
||||
for p in navmesh.polys
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class NavMeshesJs(BaseModel):
|
||||
blue: NavMeshJs
|
||||
red: NavMeshJs
|
||||
|
||||
class Config:
|
||||
title = "NavMeshes"
|
||||
|
||||
@staticmethod
|
||||
def from_game(game: Game) -> NavMeshesJs:
|
||||
return NavMeshesJs(
|
||||
blue=NavMeshJs.from_navmesh(game.blue.nav_mesh, game),
|
||||
red=NavMeshJs.from_navmesh(game.red.nav_mesh, game),
|
||||
)
|
||||
|
||||
@@ -2,21 +2,12 @@ from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
from game.server import GameContext
|
||||
from .models import NavMeshPolyJs
|
||||
from ..leaflet import ShapelyUtil
|
||||
from .models import NavMeshJs
|
||||
|
||||
router: APIRouter = APIRouter(prefix="/navmesh")
|
||||
|
||||
|
||||
@router.get("/", operation_id="get_navmesh", response_model=list[NavMeshPolyJs])
|
||||
def get(
|
||||
for_player: bool, game: Game = Depends(GameContext.require)
|
||||
) -> list[NavMeshPolyJs]:
|
||||
@router.get("/", operation_id="get_navmesh", response_model=NavMeshJs)
|
||||
def get(for_player: bool, game: Game = Depends(GameContext.require)) -> NavMeshJs:
|
||||
mesh = game.coalition_for(for_player).nav_mesh
|
||||
return [
|
||||
NavMeshPolyJs(
|
||||
poly=ShapelyUtil.poly_to_leaflet(p.poly, game.theater),
|
||||
threatened=p.threatened,
|
||||
)
|
||||
for p in mesh.polys
|
||||
]
|
||||
return NavMeshJs.from_navmesh(mesh, game)
|
||||
|
||||
Reference in New Issue
Block a user