Move NavMesh out of MapModel.

This commit is contained in:
Dan Albert
2022-02-22 18:47:51 -08:00
parent 1a9930b93a
commit 0e6a303c17
15 changed files with 108 additions and 127 deletions

View File

@@ -0,0 +1 @@
from .routes import router

View File

@@ -0,0 +1,10 @@
from __future__ import annotations
from pydantic import BaseModel
from game.server.leaflet import LeafletPoly
class NavMeshPolyJs(BaseModel):
poly: LeafletPoly
threatened: bool

View File

@@ -0,0 +1,20 @@
from fastapi import APIRouter, Depends
from game import Game
from game.server import GameContext
from .models import NavMeshPolyJs
from ..leaflet import ShapelyUtil
router: APIRouter = APIRouter(prefix="/navmesh")
@router.get("/", response_model=list[NavMeshPolyJs])
def get(for_player: bool, game: Game = Depends(GameContext.get)) -> list[NavMeshPolyJs]:
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
]