mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Update the react map for some new events.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from game import Game
|
||||
from .models import ControlPointJs
|
||||
@@ -13,3 +13,16 @@ def list_control_points(game: Game = Depends(GameContext.get)) -> list[ControlPo
|
||||
for control_point in game.theater.controlpoints:
|
||||
control_points.append(ControlPointJs.for_control_point(control_point))
|
||||
return control_points
|
||||
|
||||
|
||||
@router.get("/{cp_id}")
|
||||
def get_control_point(
|
||||
cp_id: int, game: Game = Depends(GameContext.get)
|
||||
) -> ControlPointJs:
|
||||
cp = game.theater.find_control_point_by_id(cp_id)
|
||||
if cp is None:
|
||||
raise HTTPException(
|
||||
status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Game has no control point with ID {cp_id}",
|
||||
)
|
||||
return ControlPointJs.for_control_point(cp)
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Callable, TYPE_CHECKING
|
||||
|
||||
from game.theater import MissionTarget, TheaterGroundObject
|
||||
from game.theater import ControlPoint, MissionTarget, TheaterGroundObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from game import Game
|
||||
@@ -32,9 +32,11 @@ class QtCallbacks:
|
||||
self,
|
||||
create_new_package: Callable[[MissionTarget], None],
|
||||
show_tgo_info: Callable[[TheaterGroundObject], None],
|
||||
show_control_point_info: Callable[[ControlPoint], None],
|
||||
) -> None:
|
||||
self.create_new_package = create_new_package
|
||||
self.show_tgo_info = show_tgo_info
|
||||
self.show_control_point_info = show_control_point_info
|
||||
|
||||
|
||||
class QtContext:
|
||||
|
||||
@@ -32,6 +32,7 @@ class GameUpdateEventsJs(BaseModel):
|
||||
updated_front_lines: set[UUID]
|
||||
deleted_front_lines: set[UUID]
|
||||
updated_tgos: set[UUID]
|
||||
updated_control_points: set[int]
|
||||
|
||||
@classmethod
|
||||
def from_events(cls, events: GameUpdateEvents, game: Game) -> GameUpdateEventsJs:
|
||||
@@ -64,4 +65,5 @@ class GameUpdateEventsJs(BaseModel):
|
||||
updated_front_lines=events.updated_front_lines,
|
||||
deleted_front_lines=events.deleted_front_lines,
|
||||
updated_tgos=events.updated_tgos,
|
||||
updated_control_points=events.updated_control_points,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from game import Game
|
||||
from ..dependencies import GameContext, QtCallbacks, QtContext
|
||||
@@ -33,3 +33,33 @@ def show_tgo_info(
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
qt.show_tgo_info(game.db.tgos.get(tgo_id))
|
||||
|
||||
|
||||
@router.post("/create-package/control-point/{cp_id}")
|
||||
def new_cp_package(
|
||||
cp_id: int,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
cp = game.theater.find_control_point_by_id(cp_id)
|
||||
if cp is None:
|
||||
raise HTTPException(
|
||||
status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Game has no control point with ID {cp_id}",
|
||||
)
|
||||
qt.create_new_package(cp)
|
||||
|
||||
|
||||
@router.post("/info/control-point/{cp_id}")
|
||||
def show_control_point_info(
|
||||
cp_id: int,
|
||||
game: Game = Depends(GameContext.get),
|
||||
qt: QtCallbacks = Depends(QtContext.get),
|
||||
) -> None:
|
||||
cp = game.theater.find_control_point_by_id(cp_id)
|
||||
if cp is None:
|
||||
raise HTTPException(
|
||||
status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Game has no control point with ID {cp_id}",
|
||||
)
|
||||
qt.show_control_point_info(cp)
|
||||
|
||||
Reference in New Issue
Block a user