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,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()]
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user