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

@@ -0,0 +1 @@
from .routes import router

View File

@@ -0,0 +1,35 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from pydantic import BaseModel
from game.server.controlpoints.models import ControlPointJs
from game.server.flights.models import FlightJs
from game.server.frontlines.models import FrontLineJs
from game.server.leaflet import LeafletPoint
from game.server.supplyroutes.models import SupplyRouteJs
from game.server.tgos.models import TgoJs
if TYPE_CHECKING:
from game import Game
class GameJs(BaseModel):
control_points: list[ControlPointJs]
tgos: list[TgoJs]
supply_routes: list[SupplyRouteJs]
front_lines: list[FrontLineJs]
flights: list[FlightJs]
map_center: LeafletPoint
@staticmethod
def from_game(game: Game) -> GameJs:
return GameJs(
control_points=ControlPointJs.all_in_game(game),
tgos=TgoJs.all_in_game(game),
supply_routes=SupplyRouteJs.all_in_game(game),
front_lines=FrontLineJs.all_in_game(game),
flights=FlightJs.all_in_game(game, with_waypoints=True),
map_center=game.theater.terrain.map_view_default.position.latlng(),
)

View File

@@ -0,0 +1,14 @@
from fastapi import APIRouter, Depends
from game import Game
from game.server import GameContext
from .models import GameJs
router: APIRouter = APIRouter(prefix="/game")
@router.get("/")
def game_state(game: Game | None = Depends(GameContext.get)) -> GameJs | None:
if game is None:
return None
return GameJs.from_game(game)