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,13 +1,17 @@
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 FrontLine
from game.utils import nautical_miles
if TYPE_CHECKING:
from game import Game
from game.theater import FrontLine
class FrontLineJs(BaseModel):
id: UUID
@@ -22,3 +26,7 @@ class FrontLineJs(BaseModel):
front_line.attack_heading.left.degrees, nautical_miles(2).meters
)
return FrontLineJs(id=front_line.id, extents=[a.latlng(), b.latlng()])
@staticmethod
def all_in_game(game: Game) -> list[FrontLineJs]:
return [FrontLineJs.for_front_line(f) for f in game.theater.conflicts()]

View File

@@ -10,12 +10,12 @@ router: APIRouter = APIRouter(prefix="/front-lines")
@router.get("/")
def list_front_lines(game: Game = Depends(GameContext.get)) -> list[FrontLineJs]:
return [FrontLineJs.for_front_line(f) for f in game.theater.conflicts()]
def list_front_lines(game: Game = Depends(GameContext.require)) -> list[FrontLineJs]:
return FrontLineJs.all_in_game(game)
@router.get("/{front_line_id}")
def get_front_line(
front_line_id: UUID, game: Game = Depends(GameContext.get)
front_line_id: UUID, game: Game = Depends(GameContext.require)
) -> FrontLineJs:
return FrontLineJs.for_front_line(game.db.front_lines.get(front_line_id))