mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Draw frozen combat in the new UI.
https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
8
client/src/api/combat.ts
Normal file
8
client/src/api/combat.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { LatLng } from "leaflet";
|
||||
|
||||
export default interface Combat {
|
||||
id: string;
|
||||
flight_position: LatLng | null;
|
||||
target_positions: LatLng[] | null;
|
||||
footprint: LatLng[][] | null;
|
||||
}
|
||||
42
client/src/api/combatSlice.ts
Normal file
42
client/src/api/combatSlice.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { RootState } from "../app/store";
|
||||
import Combat from "./combat";
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
interface CombatState {
|
||||
combat: { [key: string]: Combat };
|
||||
}
|
||||
|
||||
const initialState: CombatState = {
|
||||
combat: {},
|
||||
};
|
||||
|
||||
export const combatSlice = createSlice({
|
||||
name: "combat",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCombat: (state, action: PayloadAction<Combat[]>) => {
|
||||
state.combat = {};
|
||||
for (const combat of action.payload) {
|
||||
state.combat[combat.id] = combat;
|
||||
}
|
||||
},
|
||||
newCombat: (state, action: PayloadAction<Combat>) => {
|
||||
const combat = action.payload;
|
||||
state.combat[combat.id] = combat;
|
||||
},
|
||||
updateCombat: (state, action: PayloadAction<Combat>) => {
|
||||
const combat = action.payload;
|
||||
state.combat[combat.id] = combat;
|
||||
},
|
||||
endCombat: (state, action: PayloadAction<string>) => {
|
||||
delete state.combat[action.payload];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setCombat, newCombat, updateCombat, endCombat } =
|
||||
combatSlice.actions;
|
||||
|
||||
export const selectCombat = (state: RootState) => state.combat;
|
||||
|
||||
export default combatSlice.reducer;
|
||||
@@ -1,5 +1,7 @@
|
||||
import { AppDispatch } from "../app/store";
|
||||
import backend from "./backend";
|
||||
import Combat from "./combat";
|
||||
import { endCombat, newCombat, updateCombat } from "./combatSlice";
|
||||
import { updateControlPoint } from "./controlPointsSlice";
|
||||
import { ControlPoint } from "./controlpoint";
|
||||
import { Flight } from "./flight";
|
||||
@@ -21,14 +23,10 @@ import Tgo from "./tgo";
|
||||
import { updateTgo } from "./tgosSlice";
|
||||
import { LatLng } from "leaflet";
|
||||
|
||||
// Placeholder. We don't use this yet. This is just here so we can flesh out the
|
||||
// update events model.
|
||||
interface FrozenCombat {}
|
||||
|
||||
interface GameUpdateEvents {
|
||||
updated_flight_positions: { [id: string]: LatLng };
|
||||
new_combats: FrozenCombat[];
|
||||
updated_combats: FrozenCombat[];
|
||||
new_combats: Combat[];
|
||||
updated_combats: Combat[];
|
||||
ended_combats: string[];
|
||||
navmesh_updates: boolean[];
|
||||
unculled_zones_updated: boolean;
|
||||
@@ -55,6 +53,18 @@ export const handleStreamedEvents = (
|
||||
dispatch(updateFlightPosition([id, position]));
|
||||
}
|
||||
|
||||
for (const combat of events.new_combats) {
|
||||
dispatch(newCombat(combat));
|
||||
}
|
||||
|
||||
for (const combat of events.updated_combats) {
|
||||
dispatch(updateCombat(combat));
|
||||
}
|
||||
|
||||
for (const id of events.ended_combats) {
|
||||
dispatch(endCombat(id));
|
||||
}
|
||||
|
||||
for (const flight of events.new_flights) {
|
||||
dispatch(registerFlight(flight));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user