Handle IADS updates properly.

This adds the missing events in the backend, and handles them properly in the front end.
This commit is contained in:
Raffson
2022-06-30 03:58:49 +02:00
committed by GitHub
parent 5f071a6138
commit 27dff95df5
7 changed files with 47 additions and 14 deletions

View File

@@ -31,7 +31,7 @@ import { updateTgo } from "./tgosSlice";
import { threatZonesUpdated } from "./threatZonesSlice";
import { unculledZonesUpdated } from "./unculledZonesSlice";
import { LatLng } from "leaflet";
import { updateIadsConnection } from "./iadsNetworkSlice";
import { updateIadsConnection, removeIadsConnection } from "./iadsNetworkSlice";
interface GameUpdateEvents {
updated_flight_positions: { [id: string]: LatLng };
@@ -50,6 +50,8 @@ interface GameUpdateEvents {
deleted_front_lines: string[];
updated_tgos: string[];
updated_control_points: ControlPoint[];
updated_iads: IadsConnection[];
deleted_iads: string[];
reset_on_map_center: LatLng | null;
game_unloaded: boolean;
new_turn: boolean;
@@ -134,17 +136,20 @@ export const handleStreamedEvents = (
const tgo = response.data as Tgo;
dispatch(updateTgo(tgo));
});
backend.get(`/iads-network/for-tgo/${id}`).then((response) => {
for (const connection of response.data) {
dispatch(updateIadsConnection(connection as IadsConnection));
}
});
}
if (events.updated_control_points.length > 0) {
dispatch(updateControlPoint(events.updated_control_points));
}
if (events.deleted_iads.length > 0) {
dispatch(removeIadsConnection(events.deleted_iads));
}
if (events.updated_iads.length > 0) {
dispatch(updateIadsConnection(events.updated_iads));
}
if (events.reset_on_map_center != null) {
reloadGameState(dispatch);
}

View File

@@ -15,10 +15,16 @@ export const IadsNetworkSlice = createSlice({
name: "iadsNetwork",
initialState,
reducers: {
updateIadsConnection: (state, action: PayloadAction<IadsConnection>) => {
const connection = action.payload;
state.connections[connection.id] = connection
updateIadsConnection: (state, action: PayloadAction<IadsConnection[]>) => {
for (const connection of action.payload) {
state.connections[connection.id] = connection
}
},
removeIadsConnection: (state, action: PayloadAction<string[]>) => {
for (const cID of action.payload) {
delete state.connections[cID];
}
}
},
extraReducers: (builder) => {
builder.addCase(gameLoaded, (state, action) => {
@@ -36,7 +42,7 @@ export const IadsNetworkSlice = createSlice({
},
});
export const { updateIadsConnection } = IadsNetworkSlice.actions;
export const { updateIadsConnection, removeIadsConnection } = IadsNetworkSlice.actions;
export const selectIadsNetwork = (state: RootState) => state.iadsNetwork;