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
game/server/game/__init__.py
Normal file
1
game/server/game/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .routes import router
|
||||
35
game/server/game/models.py
Normal file
35
game/server/game/models.py
Normal 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(),
|
||||
)
|
||||
14
game/server/game/routes.py
Normal file
14
game/server/game/routes.py
Normal 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)
|
||||
Reference in New Issue
Block a user