mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Push full navmesh/threatzone info in the event stream.
https://github.com/dcs-liberation/dcs_liberation/issues/2253 https://github.com/dcs-liberation/dcs_liberation/issues/2263
This commit is contained in:
@@ -17,12 +17,13 @@ import {
|
||||
} from "./frontLinesSlice";
|
||||
import reloadGameState from "./gamestate";
|
||||
import {
|
||||
liberationApi,
|
||||
ControlPoint,
|
||||
Flight,
|
||||
FrontLine,
|
||||
IadsConnection,
|
||||
NavMesh,
|
||||
Tgo,
|
||||
ThreatZones,
|
||||
UnculledZone,
|
||||
} from "./liberationApi";
|
||||
import { navMeshUpdated } from "./navMeshSlice";
|
||||
@@ -37,9 +38,9 @@ interface GameUpdateEvents {
|
||||
new_combats: Combat[];
|
||||
updated_combats: Combat[];
|
||||
ended_combats: string[];
|
||||
navmesh_updates: boolean[];
|
||||
navmesh_updates: {blue: boolean, mesh: NavMesh}[];
|
||||
updated_unculled_zones: UnculledZone[];
|
||||
threat_zones_updated: boolean;
|
||||
threat_zones_updated: {blue: boolean, zones: ThreatZones}[];
|
||||
new_flights: Flight[];
|
||||
updated_flights: Flight[];
|
||||
deleted_flights: string[];
|
||||
@@ -78,28 +79,16 @@ export const handleStreamedEvents = (
|
||||
dispatch(endCombat(id));
|
||||
}
|
||||
|
||||
for (const blue of events.navmesh_updates) {
|
||||
dispatch(
|
||||
liberationApi.endpoints.getNavmesh.initiate({ forPlayer: blue })
|
||||
).then((result) => {
|
||||
if (result.data) {
|
||||
dispatch(navMeshUpdated({ blue: blue, mesh: result.data }));
|
||||
}
|
||||
});
|
||||
if (Object.keys(events.navmesh_updates).length > 0) {
|
||||
dispatch(navMeshUpdated(events.navmesh_updates));
|
||||
}
|
||||
|
||||
if (events.updated_unculled_zones.length > 0) {
|
||||
dispatch(unculledZonesUpdated(events.updated_unculled_zones));
|
||||
}
|
||||
|
||||
if (events.threat_zones_updated) {
|
||||
dispatch(liberationApi.endpoints.getThreatZones.initiate()).then(
|
||||
(result) => {
|
||||
if (result.data) {
|
||||
dispatch(threatZonesUpdated(result.data));
|
||||
}
|
||||
}
|
||||
);
|
||||
if (Object.keys(events.threat_zones_updated).length > 0) {
|
||||
dispatch(threatZonesUpdated(events.threat_zones_updated));
|
||||
}
|
||||
|
||||
if (events.new_flights.length > 0) {
|
||||
|
||||
@@ -13,7 +13,7 @@ const initialState: NavMeshState = {
|
||||
red: [],
|
||||
};
|
||||
|
||||
interface INavMeshUpdate {
|
||||
export interface INavMeshUpdate {
|
||||
blue: boolean;
|
||||
mesh: NavMesh;
|
||||
}
|
||||
@@ -22,12 +22,15 @@ const navMeshSlice = createSlice({
|
||||
name: "navmesh",
|
||||
initialState: initialState,
|
||||
reducers: {
|
||||
updated: (state, action: PayloadAction<INavMeshUpdate>) => {
|
||||
const polys = action.payload.mesh.polys;
|
||||
if (action.payload.blue) {
|
||||
state.blue = polys;
|
||||
} else {
|
||||
state.red = polys;
|
||||
updated: (state, action: PayloadAction<INavMeshUpdate[]>) => {
|
||||
for (const [blue, navmesh] of Object.entries(action.payload)) {
|
||||
const data = {blue: (blue === "true"), mesh: navmesh} as unknown as INavMeshUpdate
|
||||
const polys = data.mesh.polys;
|
||||
if (data.blue) {
|
||||
state.blue = polys;
|
||||
} else {
|
||||
state.red = polys;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { RootState } from "../app/store";
|
||||
import { gameLoaded, gameUnloaded } from "./actions";
|
||||
import { ThreatZoneContainer } from "./liberationApi";
|
||||
import { ThreatZoneContainer, ThreatZones } from "./liberationApi";
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
interface ThreatZonesState {
|
||||
@@ -24,12 +24,24 @@ const initialState: ThreatZonesState = {
|
||||
},
|
||||
};
|
||||
|
||||
export interface IThreatZoneUpdate {
|
||||
blue: boolean;
|
||||
zones: ThreatZones;
|
||||
}
|
||||
|
||||
export const threatZonesSlice = createSlice({
|
||||
name: "threatZonesState",
|
||||
initialState,
|
||||
reducers: {
|
||||
updated: (state, action: PayloadAction<ThreatZoneContainer>) => {
|
||||
state.zones = action.payload;
|
||||
updated: (state, action: PayloadAction<IThreatZoneUpdate[]>) => {
|
||||
for (const [blue, zones] of Object.entries(action.payload)) {
|
||||
const data = {blue: (blue === "true"), zones: zones} as unknown as IThreatZoneUpdate
|
||||
if (data.blue) {
|
||||
state.zones.blue = data.zones;
|
||||
} else {
|
||||
state.zones.red = data.zones;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
|
||||
Reference in New Issue
Block a user