Move TGOs out of MapModel.

This commit is contained in:
Dan Albert
2022-03-03 17:10:12 -08:00
parent d0ad554e14
commit c5c596dc2f
19 changed files with 186 additions and 186 deletions

View File

@@ -9,7 +9,7 @@ from . import (
frontlines,
mapzones,
navmesh,
packagedialog,
qt,
supplyroutes,
tgos,
waypoints,
@@ -29,7 +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(qt.router)
app.include_router(supplyroutes.router)
app.include_router(tgos.router)
app.include_router(waypoints.router)

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import Callable, TYPE_CHECKING
from game.theater import MissionTarget
from game.theater import MissionTarget, TheaterGroundObject
if TYPE_CHECKING:
from game import Game
@@ -28,8 +28,13 @@ class GameContext:
class QtCallbacks:
def __init__(self, create_new_package: Callable[[MissionTarget], None]) -> None:
def __init__(
self,
create_new_package: Callable[[MissionTarget], None],
show_tgo_info: Callable[[TheaterGroundObject], None],
) -> None:
self.create_new_package = create_new_package
self.show_tgo_info = show_tgo_info
class QtContext:

View File

@@ -31,6 +31,7 @@ class GameUpdateEventsJs(BaseModel):
new_front_lines: list[FrontLineJs]
updated_front_lines: set[UUID]
deleted_front_lines: set[UUID]
updated_tgos: set[UUID]
@classmethod
def from_events(cls, events: GameUpdateEvents, game: Game) -> GameUpdateEventsJs:
@@ -62,4 +63,5 @@ class GameUpdateEventsJs(BaseModel):
],
updated_front_lines=events.updated_front_lines,
deleted_front_lines=events.deleted_front_lines,
updated_tgos=events.updated_tgos,
)

View File

@@ -1,18 +0,0 @@
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)

35
game/server/qt/routes.py Normal file
View File

@@ -0,0 +1,35 @@
from uuid import UUID
from fastapi import APIRouter, Depends
from game import Game
from ..dependencies import GameContext, QtCallbacks, QtContext
router: APIRouter = APIRouter(prefix="/qt")
@router.post("/create-package/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:
qt.create_new_package(game.db.front_lines.get(front_line_id))
@router.post("/create-package/tgo/{tgo_id}")
def new_tgo_package(
tgo_id: UUID,
game: Game = Depends(GameContext.get),
qt: QtCallbacks = Depends(QtContext.get),
) -> None:
qt.create_new_package(game.db.tgos.get(tgo_id))
@router.post("/info/tgo/{tgo_id}")
def show_tgo_info(
tgo_id: UUID,
game: Game = Depends(GameContext.get),
qt: QtCallbacks = Depends(QtContext.get),
) -> None:
qt.show_tgo_info(game.db.tgos.get(tgo_id))

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from uuid import UUID
from pydantic import BaseModel
from game.server.leaflet import LeafletPoint
@@ -7,16 +9,17 @@ from game.theater import TheaterGroundObject
class TgoJs(BaseModel):
id: UUID
name: str
control_point_name: str
category: str
blue: bool
position: LeafletPoint
units: list[str]
threat_ranges: list[float]
detection_ranges: list[float]
dead: bool
sidc: str
units: list[str] # TODO: Event stream
threat_ranges: list[float] # TODO: Event stream
detection_ranges: list[float] # TODO: Event stream
dead: bool # TODO: Event stream
sidc: str # TODO: Event stream
@staticmethod
def for_tgo(tgo: TheaterGroundObject) -> TgoJs:
@@ -29,6 +32,7 @@ class TgoJs(BaseModel):
tgo.detection_range(group).meters for group in tgo.groups
]
return TgoJs(
id=tgo.id,
name=tgo.name,
control_point_name=tgo.control_point.name,
category=tgo.category,

View File

@@ -1,3 +1,5 @@
from uuid import UUID
from fastapi import APIRouter, Depends
from game import Game
@@ -15,3 +17,8 @@ def list_tgos(game: Game = Depends(GameContext.get)) -> list[TgoJs]:
if not tgo.is_control_point:
tgos.append(TgoJs.for_tgo(tgo))
return tgos
@router.get("/{tgo_id}")
def get_tgo(tgo_id: UUID, game: Game = Depends(GameContext.get)) -> TgoJs:
return TgoJs.for_tgo(game.db.tgos.get(tgo_id))