mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Push full control point information in the event stream.
https://github.com/dcs-liberation/dcs_liberation/issues/2263
This commit is contained in:
parent
da90a40bc4
commit
61488627a4
@ -15,9 +15,10 @@ export const controlPointsSlice = createSlice({
|
||||
name: "controlPoints",
|
||||
initialState,
|
||||
reducers: {
|
||||
updateControlPoint: (state, action: PayloadAction<ControlPoint>) => {
|
||||
const cp = action.payload;
|
||||
state.controlPoints[cp.id] = cp;
|
||||
updateControlPoint: (state, action: PayloadAction<ControlPoint[]>) => {
|
||||
for (const cp of action.payload) {
|
||||
state.controlPoints[cp.id] = cp;
|
||||
}
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
|
||||
@ -49,7 +49,7 @@ interface GameUpdateEvents {
|
||||
updated_front_lines: FrontLine[];
|
||||
deleted_front_lines: string[];
|
||||
updated_tgos: string[];
|
||||
updated_control_points: number[];
|
||||
updated_control_points: ControlPoint[];
|
||||
reset_on_map_center: LatLng | null;
|
||||
game_unloaded: boolean;
|
||||
new_turn: boolean;
|
||||
@ -141,11 +141,8 @@ export const handleStreamedEvents = (
|
||||
});
|
||||
}
|
||||
|
||||
for (const id of events.updated_control_points) {
|
||||
backend.get(`/control-points/${id}`).then((response) => {
|
||||
const cp = response.data as ControlPoint;
|
||||
dispatch(updateControlPoint(cp));
|
||||
});
|
||||
if (events.updated_control_points.length > 0) {
|
||||
dispatch(updateControlPoint(events.updated_control_points));
|
||||
}
|
||||
|
||||
if (events.reset_on_map_center != null) {
|
||||
|
||||
@ -6,10 +6,8 @@ from fastapi import APIRouter, Body, Depends, HTTPException, status
|
||||
|
||||
from game import Game
|
||||
from .models import ControlPointJs
|
||||
from .. import EventStream
|
||||
from ..dependencies import GameContext
|
||||
from ..leaflet import LeafletPoint
|
||||
from ...sim import GameUpdateEvents
|
||||
|
||||
router: APIRouter = APIRouter(prefix="/control-points")
|
||||
|
||||
@ -90,7 +88,10 @@ def set_destination(
|
||||
f"{cp.max_move_distance.nautical_miles}nm.",
|
||||
)
|
||||
cp.target_position = point
|
||||
EventStream.put_nowait(GameUpdateEvents().update_control_point(cp))
|
||||
from .. import EventStream
|
||||
|
||||
with EventStream.event_context() as events:
|
||||
events.update_control_point(cp)
|
||||
|
||||
|
||||
@router.put(
|
||||
@ -113,4 +114,7 @@ def cancel_travel(cp_id: UUID, game: Game = Depends(GameContext.require)) -> Non
|
||||
)
|
||||
|
||||
cp.target_position = None
|
||||
EventStream.put_nowait(GameUpdateEvents().update_control_point(cp))
|
||||
from .. import EventStream
|
||||
|
||||
with EventStream.event_context() as events:
|
||||
events.update_control_point(cp)
|
||||
|
||||
@ -6,6 +6,7 @@ from uuid import UUID
|
||||
from pydantic import BaseModel
|
||||
|
||||
from game.server.combat.models import FrozenCombatJs
|
||||
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
|
||||
@ -32,7 +33,7 @@ class GameUpdateEventsJs(BaseModel):
|
||||
updated_front_lines: list[FrontLineJs]
|
||||
deleted_front_lines: set[UUID]
|
||||
updated_tgos: set[UUID]
|
||||
updated_control_points: set[UUID]
|
||||
updated_control_points: list[ControlPointJs]
|
||||
reset_on_map_center: LeafletPoint | None
|
||||
game_unloaded: bool
|
||||
new_turn: bool
|
||||
@ -82,7 +83,10 @@ class GameUpdateEventsJs(BaseModel):
|
||||
],
|
||||
deleted_front_lines=events.deleted_front_lines,
|
||||
updated_tgos=events.updated_tgos,
|
||||
updated_control_points=events.updated_control_points,
|
||||
updated_control_points=[
|
||||
ControlPointJs.for_control_point(cp)
|
||||
for cp in events.updated_control_points
|
||||
],
|
||||
reset_on_map_center=events.reset_on_map_center,
|
||||
game_unloaded=events.game_unloaded,
|
||||
new_turn=events.new_turn,
|
||||
|
||||
@ -32,7 +32,7 @@ class GameUpdateEvents:
|
||||
updated_front_lines: set[FrontLine] = field(default_factory=set)
|
||||
deleted_front_lines: set[UUID] = field(default_factory=set)
|
||||
updated_tgos: set[UUID] = field(default_factory=set)
|
||||
updated_control_points: set[UUID] = field(default_factory=set)
|
||||
updated_control_points: set[ControlPoint] = field(default_factory=set)
|
||||
reset_on_map_center: LatLng | None = None
|
||||
game_unloaded: bool = False
|
||||
new_turn: bool = False
|
||||
@ -118,7 +118,7 @@ class GameUpdateEvents:
|
||||
return self
|
||||
|
||||
def update_control_point(self, control_point: ControlPoint) -> GameUpdateEvents:
|
||||
self.updated_control_points.add(control_point.id)
|
||||
self.updated_control_points.add(control_point)
|
||||
return self
|
||||
|
||||
def game_loaded(self, game: Game | None) -> GameUpdateEvents:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user