mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Move NavMesh out of MapModel.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from fastapi import Depends, FastAPI
|
||||
|
||||
from . import debuggeometries, eventstream, flights, waypoints
|
||||
from . import debuggeometries, eventstream, flights, navmesh, waypoints
|
||||
from .security import ApiKeyManager
|
||||
|
||||
app = FastAPI(dependencies=[Depends(ApiKeyManager.verify)])
|
||||
app.include_router(debuggeometries.router)
|
||||
app.include_router(eventstream.router)
|
||||
app.include_router(flights.router)
|
||||
app.include_router(navmesh.router)
|
||||
app.include_router(waypoints.router)
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
from game import Game
|
||||
from qt_ui.models import GameModel
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
from qt_ui.models import GameModel
|
||||
|
||||
|
||||
class GameContext:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from asyncio import Queue
|
||||
|
||||
from game.sim.gameupdateevents import GameUpdateEvents
|
||||
from game.sim import GameUpdateEvents
|
||||
|
||||
|
||||
class EventStream:
|
||||
|
||||
@@ -10,13 +10,14 @@ from game.server.leaflet import LeafletLatLon
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
from game.sim.gameupdateevents import GameUpdateEvents
|
||||
from game.sim import GameUpdateEvents
|
||||
|
||||
|
||||
class GameUpdateEventsJs(BaseModel):
|
||||
updated_flights: dict[UUID, LeafletLatLon]
|
||||
new_combats: list[FrozenCombatJs] = []
|
||||
updated_combats: list[FrozenCombatJs] = []
|
||||
navmesh_updates: set[bool] = set()
|
||||
|
||||
@classmethod
|
||||
def from_events(cls, events: GameUpdateEvents, game: Game) -> GameUpdateEventsJs:
|
||||
@@ -31,4 +32,5 @@ class GameUpdateEventsJs(BaseModel):
|
||||
FrozenCombatJs.for_combat(c, game.theater)
|
||||
for c in events.updated_combats
|
||||
],
|
||||
navmesh_updates=events.navmesh_updates,
|
||||
)
|
||||
|
||||
1
game/server/navmesh/__init__.py
Normal file
1
game/server/navmesh/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .routes import router
|
||||
10
game/server/navmesh/models.py
Normal file
10
game/server/navmesh/models.py
Normal 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
|
||||
20
game/server/navmesh/routes.py
Normal file
20
game/server/navmesh/routes.py
Normal 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
|
||||
]
|
||||
Reference in New Issue
Block a user