mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Move front lines out of MapModel.
This commit is contained in:
@@ -9,6 +9,7 @@ from . import (
|
||||
frontlines,
|
||||
mapzones,
|
||||
navmesh,
|
||||
packagedialog,
|
||||
supplyroutes,
|
||||
tgos,
|
||||
waypoints,
|
||||
@@ -28,6 +29,7 @@ app.include_router(flights.router)
|
||||
app.include_router(frontlines.router)
|
||||
app.include_router(mapzones.router)
|
||||
app.include_router(navmesh.router)
|
||||
app.include_router(packagedialog.router)
|
||||
app.include_router(supplyroutes.router)
|
||||
app.include_router(tgos.router)
|
||||
app.include_router(waypoints.router)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Callable, TYPE_CHECKING
|
||||
|
||||
from game.theater import MissionTarget
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
@@ -23,3 +25,22 @@ class GameContext:
|
||||
@classmethod
|
||||
def get_model(cls) -> GameModel:
|
||||
return cls._game_model
|
||||
|
||||
|
||||
class QtCallbacks:
|
||||
def __init__(self, create_new_package: Callable[[MissionTarget], None]) -> None:
|
||||
self.create_new_package = create_new_package
|
||||
|
||||
|
||||
class QtContext:
|
||||
_callbacks: QtCallbacks
|
||||
|
||||
@classmethod
|
||||
def set_callbacks(cls, callbacks: QtCallbacks) -> None:
|
||||
cls._callbacks = callbacks
|
||||
|
||||
@classmethod
|
||||
def get(cls) -> QtCallbacks:
|
||||
if cls._callbacks is None:
|
||||
raise RuntimeError("QtContext has no callbacks set")
|
||||
return cls._callbacks
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import BaseModel
|
||||
|
||||
from game.server.combat.models import FrozenCombatJs
|
||||
from game.server.flights.models import FlightJs
|
||||
from game.server.frontlines.models import FrontLineJs
|
||||
from game.server.leaflet import LeafletLatLon
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -27,6 +28,9 @@ class GameUpdateEventsJs(BaseModel):
|
||||
deleted_flights: set[UUID]
|
||||
selected_flight: UUID | None
|
||||
deselected_flight: bool
|
||||
new_front_lines: list[FrontLineJs]
|
||||
updated_front_lines: set[UUID]
|
||||
deleted_front_lines: set[UUID]
|
||||
|
||||
@classmethod
|
||||
def from_events(cls, events: GameUpdateEvents, game: Game) -> GameUpdateEventsJs:
|
||||
@@ -53,4 +57,9 @@ class GameUpdateEventsJs(BaseModel):
|
||||
deleted_flights=events.deleted_flights,
|
||||
selected_flight=events.selected_flight,
|
||||
deselected_flight=events.deselected_flight,
|
||||
new_front_lines=[
|
||||
FrontLineJs.for_front_line(f) for f in events.new_front_lines
|
||||
],
|
||||
updated_front_lines=events.updated_front_lines,
|
||||
deleted_front_lines=events.deleted_front_lines,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
from __future__ import annotations
|
||||
|
||||
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
|
||||
|
||||
|
||||
class FrontLineJs(BaseModel):
|
||||
id: UUID
|
||||
extents: list[LeafletPoint]
|
||||
|
||||
@staticmethod
|
||||
def for_front_line(front_line: FrontLine) -> FrontLineJs:
|
||||
a = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.right.degrees, nautical_miles(2).meters
|
||||
)
|
||||
b = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.left.degrees, nautical_miles(2).meters
|
||||
)
|
||||
return FrontLineJs(id=front_line.id, extents=[a.latlng(), b.latlng()])
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
from game.utils import nautical_miles
|
||||
from .models import FrontLineJs
|
||||
from ..dependencies import GameContext
|
||||
|
||||
@@ -10,13 +11,11 @@ router: APIRouter = APIRouter(prefix="/front-lines")
|
||||
|
||||
@router.get("/")
|
||||
def list_front_lines(game: Game = Depends(GameContext.get)) -> list[FrontLineJs]:
|
||||
front_lines = []
|
||||
for front_line in game.theater.conflicts():
|
||||
a = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.right.degrees, nautical_miles(2).meters
|
||||
)
|
||||
b = front_line.position.point_from_heading(
|
||||
front_line.attack_heading.left.degrees, nautical_miles(2).meters
|
||||
)
|
||||
front_lines.append(FrontLineJs(extents=[a.latlng(), b.latlng()]))
|
||||
return front_lines
|
||||
return [FrontLineJs.for_front_line(f) for f in game.theater.conflicts()]
|
||||
|
||||
|
||||
@router.get("/{front_line_id}")
|
||||
def get_front_line(
|
||||
front_line_id: UUID, game: Game = Depends(GameContext.get)
|
||||
) -> FrontLineJs:
|
||||
return FrontLineJs.for_front_line(game.db.front_lines.get(front_line_id))
|
||||
|
||||
1
game/server/packagedialog/__init__.py
Normal file
1
game/server/packagedialog/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .routes import router
|
||||
18
game/server/packagedialog/routes.py
Normal file
18
game/server/packagedialog/routes.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from game import Game
|
||||
from ..dependencies import GameContext, QtCallbacks, QtContext
|
||||
|
||||
router: APIRouter = APIRouter(prefix="/package-dialog")
|
||||
|
||||
|
||||
@router.post("/front-line/{front_line_id}")
|
||||
def new_front_line_package(
|
||||
front_line_id: UUID,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
front_line = game.db.front_lines.get(front_line_id)
|
||||
qt.create_new_package(front_line)
|
||||
Reference in New Issue
Block a user