mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user