mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Push full flight information in the event stream.
https://github.com/dcs-liberation/dcs_liberation/issues/2263
This commit is contained in:
@@ -6,10 +6,10 @@ import { endCombat, newCombat, updateCombat } from "./combatSlice";
|
||||
import { updateControlPoint } from "./controlPointsSlice";
|
||||
import {
|
||||
deselectFlight,
|
||||
registerFlight,
|
||||
registerFlights,
|
||||
selectFlight,
|
||||
unregisterFlight,
|
||||
updateFlight,
|
||||
unregisterFlights,
|
||||
updateFlights,
|
||||
updateFlightPositions,
|
||||
} from "./flightsSlice";
|
||||
import {
|
||||
@@ -43,7 +43,7 @@ interface GameUpdateEvents {
|
||||
updated_unculled_zones: UnculledZone[];
|
||||
threat_zones_updated: boolean;
|
||||
new_flights: Flight[];
|
||||
updated_flights: string[];
|
||||
updated_flights: Flight[];
|
||||
deleted_flights: string[];
|
||||
selected_flight: string | null;
|
||||
deselected_flight: boolean;
|
||||
@@ -103,19 +103,16 @@ export const handleStreamedEvents = (
|
||||
);
|
||||
}
|
||||
|
||||
for (const flight of events.new_flights) {
|
||||
dispatch(registerFlight(flight));
|
||||
if (events.new_flights.length > 0) {
|
||||
dispatch(registerFlights(events.new_flights));
|
||||
}
|
||||
|
||||
for (const id of events.updated_flights) {
|
||||
backend.get(`/flights/${id}?with_waypoints=true`).then((response) => {
|
||||
const flight = response.data as Flight;
|
||||
dispatch(updateFlight(flight));
|
||||
});
|
||||
if (events.updated_flights.length > 0) {
|
||||
dispatch(updateFlights(events.updated_flights));
|
||||
}
|
||||
|
||||
for (const id of events.deleted_flights) {
|
||||
dispatch(unregisterFlight(id));
|
||||
if (events.deleted_flights.length > 0) {
|
||||
dispatch(unregisterFlights(events.deleted_flights));
|
||||
}
|
||||
|
||||
if (events.deselected_flight) {
|
||||
|
||||
@@ -18,20 +18,23 @@ export const flightsSlice = createSlice({
|
||||
name: "flights",
|
||||
initialState,
|
||||
reducers: {
|
||||
registerFlight: (state, action: PayloadAction<Flight>) => {
|
||||
const flight = action.payload;
|
||||
if (flight.id in state.flights) {
|
||||
console.log(`Overriding flight with ID: ${flight.id}`);
|
||||
registerFlights: (state, action: PayloadAction<Flight[]>) => {
|
||||
for (const flight of action.payload) {
|
||||
if (flight.id in state.flights) {
|
||||
console.log(`Overriding flight with ID: ${flight.id}`);
|
||||
}
|
||||
state.flights[flight.id] = flight;
|
||||
}
|
||||
state.flights[flight.id] = flight;
|
||||
},
|
||||
unregisterFlight: (state, action: PayloadAction<string>) => {
|
||||
const id = action.payload;
|
||||
delete state.flights[id];
|
||||
unregisterFlights: (state, action: PayloadAction<string[]>) => {
|
||||
for (const id of action.payload) {
|
||||
delete state.flights[id];
|
||||
}
|
||||
},
|
||||
updateFlight: (state, action: PayloadAction<Flight>) => {
|
||||
const flight = action.payload;
|
||||
state.flights[flight.id] = flight;
|
||||
updateFlights: (state, action: PayloadAction<Flight[]>) => {
|
||||
for (const flight of action.payload) {
|
||||
state.flights[flight.id] = flight;
|
||||
}
|
||||
},
|
||||
deselectFlight: (state) => {
|
||||
state.selected = null;
|
||||
@@ -67,9 +70,9 @@ export const flightsSlice = createSlice({
|
||||
});
|
||||
|
||||
export const {
|
||||
registerFlight,
|
||||
unregisterFlight,
|
||||
updateFlight,
|
||||
registerFlights,
|
||||
unregisterFlights,
|
||||
updateFlights,
|
||||
deselectFlight,
|
||||
selectFlight,
|
||||
updateFlightPositions,
|
||||
|
||||
Reference in New Issue
Block a user