Handle map reset when the game is loaded/unloaded.

https://github.com/dcs-liberation/dcs_liberation/issues/2039

Partial fix for
https://github.com/dcs-liberation/dcs_liberation/issues/2045 (now works
in the new map, old one not fixed yet).
This commit is contained in:
Dan Albert
2022-03-05 18:02:46 -08:00
parent 995e28cb32
commit 73fcfcec7b
37 changed files with 403 additions and 178 deletions

View File

@@ -1,9 +1,14 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from pydantic import BaseModel
from game.server.leaflet import LeafletPoint
from game.theater import ControlPoint
if TYPE_CHECKING:
from game import Game
from game.theater import ControlPoint
class ControlPointJs(BaseModel):
@@ -29,3 +34,9 @@ class ControlPointJs(BaseModel):
destination=destination,
sidc=str(control_point.sidc()),
)
@staticmethod
def all_in_game(game: Game) -> list[ControlPointJs]:
return [
ControlPointJs.for_control_point(cp) for cp in game.theater.controlpoints
]

View File

@@ -13,16 +13,15 @@ router: APIRouter = APIRouter(prefix="/control-points")
@router.get("/")
def list_control_points(game: Game = Depends(GameContext.get)) -> list[ControlPointJs]:
control_points = []
for control_point in game.theater.controlpoints:
control_points.append(ControlPointJs.for_control_point(control_point))
return control_points
def list_control_points(
game: Game = Depends(GameContext.require),
) -> list[ControlPointJs]:
return ControlPointJs.all_in_game(game)
@router.get("/{cp_id}")
def get_control_point(
cp_id: int, game: Game = Depends(GameContext.get)
cp_id: int, game: Game = Depends(GameContext.require)
) -> ControlPointJs:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
@@ -35,7 +34,7 @@ def get_control_point(
@router.get("/{cp_id}/destination-in-range")
def destination_in_range(
cp_id: int, lat: float, lng: float, game: Game = Depends(GameContext.get)
cp_id: int, lat: float, lng: float, game: Game = Depends(GameContext.require)
) -> bool:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
@@ -50,7 +49,7 @@ def destination_in_range(
@router.put("/{cp_id}/destination")
def set_destination(
cp_id: int, destination: LeafletPoint, game: Game = Depends(GameContext.get)
cp_id: int, destination: LeafletPoint, game: Game = Depends(GameContext.require)
) -> None:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
@@ -79,7 +78,7 @@ def set_destination(
@router.put("/{cp_id}/cancel-travel")
def cancel_travel(cp_id: int, game: Game = Depends(GameContext.get)) -> None:
def cancel_travel(cp_id: int, game: Game = Depends(GameContext.require)) -> None:
cp = game.theater.find_control_point_by_id(cp_id)
if cp is None:
raise HTTPException(