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,11 +1,15 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from uuid import UUID
from pydantic import BaseModel
from game.server.leaflet import LeafletPoint
from game.theater import TheaterGroundObject
if TYPE_CHECKING:
from game import Game
from game.theater import TheaterGroundObject
class TgoJs(BaseModel):
@@ -44,3 +48,12 @@ class TgoJs(BaseModel):
dead=tgo.is_dead,
sidc=str(tgo.sidc()),
)
@staticmethod
def all_in_game(game: Game) -> list[TgoJs]:
tgos = []
for control_point in game.theater.controlpoints:
for tgo in control_point.connected_objectives:
if not tgo.is_control_point:
tgos.append(TgoJs.for_tgo(tgo))
return tgos

View File

@@ -10,15 +10,10 @@ router: APIRouter = APIRouter(prefix="/tgos")
@router.get("/")
def list_tgos(game: Game = Depends(GameContext.get)) -> list[TgoJs]:
tgos = []
for control_point in game.theater.controlpoints:
for tgo in control_point.connected_objectives:
if not tgo.is_control_point:
tgos.append(TgoJs.for_tgo(tgo))
return tgos
def list_tgos(game: Game = Depends(GameContext.require)) -> list[TgoJs]:
return TgoJs.all_in_game(game)
@router.get("/{tgo_id}")
def get_tgo(tgo_id: UUID, game: Game = Depends(GameContext.get)) -> TgoJs:
def get_tgo(tgo_id: UUID, game: Game = Depends(GameContext.require)) -> TgoJs:
return TgoJs.for_tgo(game.db.tgos.get(tgo_id))