mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add navmesh support to the new map.
https://github.com/dcs-liberation/dcs_liberation/issues/2039
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
import FrontLine from "./frontline";
|
||||
import reloadGameState from "./gamestate";
|
||||
import { liberationApi } from "./liberationApi";
|
||||
import { navMeshUpdated } from "./navMeshSlice";
|
||||
import Tgo from "./tgo";
|
||||
import { updateTgo } from "./tgosSlice";
|
||||
import { threatZonesUpdated } from "./threatZonesSlice";
|
||||
@@ -72,6 +73,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 (events.threat_zones_updated) {
|
||||
dispatch(liberationApi.endpoints.getThreatZones.initiate()).then(
|
||||
(result) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ControlPoint } from "./controlpoint";
|
||||
import { Flight } from "./flight";
|
||||
import FrontLine from "./frontline";
|
||||
import { ThreatZoneContainer } from "./liberationApi";
|
||||
import { NavMeshes, ThreatZoneContainer } from "./liberationApi";
|
||||
import SupplyRoute from "./supplyroute";
|
||||
import Tgo from "./tgo";
|
||||
import { LatLngLiteral } from "leaflet";
|
||||
@@ -13,5 +13,6 @@ export default interface Game {
|
||||
front_lines: FrontLine[];
|
||||
flights: Flight[];
|
||||
threat_zones: ThreatZoneContainer;
|
||||
navmeshes: NavMeshes;
|
||||
map_center: LatLngLiteral | null;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ export type GetThreatZonesApiResponse =
|
||||
/** status 200 Successful Response */ ThreatZoneContainer;
|
||||
export type GetThreatZonesApiArg = void;
|
||||
export type GetNavmeshApiResponse =
|
||||
/** status 200 Successful Response */ NavMeshPoly[];
|
||||
/** status 200 Successful Response */ NavMesh;
|
||||
export type GetNavmeshApiArg = {
|
||||
forPlayer: boolean;
|
||||
};
|
||||
@@ -414,23 +414,6 @@ export type SupplyRoute = {
|
||||
blue: boolean;
|
||||
active_transports: string[];
|
||||
};
|
||||
export type Game = {
|
||||
control_points: ControlPoint[];
|
||||
tgos: Tgo[];
|
||||
supply_routes: SupplyRoute[];
|
||||
front_lines: FrontLine[];
|
||||
flights: Flight[];
|
||||
map_center: LatLng;
|
||||
};
|
||||
export type MapZones = {
|
||||
inclusion: number[][][];
|
||||
exclusion: number[][][];
|
||||
sea: number[][][];
|
||||
};
|
||||
export type UnculledZone = {
|
||||
position: LatLng;
|
||||
radius: number;
|
||||
};
|
||||
export type ThreatZones = {
|
||||
full: number[][][];
|
||||
aircraft: number[][][];
|
||||
@@ -445,6 +428,32 @@ export type NavMeshPoly = {
|
||||
poly: number[][];
|
||||
threatened: boolean;
|
||||
};
|
||||
export type NavMesh = {
|
||||
polys: NavMeshPoly[];
|
||||
};
|
||||
export type NavMeshes = {
|
||||
blue: NavMesh;
|
||||
red: NavMesh;
|
||||
};
|
||||
export type Game = {
|
||||
control_points: ControlPoint[];
|
||||
tgos: Tgo[];
|
||||
supply_routes: SupplyRoute[];
|
||||
front_lines: FrontLine[];
|
||||
flights: Flight[];
|
||||
threat_zones: ThreatZoneContainer;
|
||||
navmeshes: NavMeshes;
|
||||
map_center: LatLng;
|
||||
};
|
||||
export type MapZones = {
|
||||
inclusion: number[][][];
|
||||
exclusion: number[][][];
|
||||
sea: number[][][];
|
||||
};
|
||||
export type UnculledZone = {
|
||||
position: LatLng;
|
||||
radius: number;
|
||||
};
|
||||
export const {
|
||||
useListControlPointsQuery,
|
||||
useGetControlPointByIdQuery,
|
||||
|
||||
50
client/src/api/navMeshSlice.ts
Normal file
50
client/src/api/navMeshSlice.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { RootState } from "../app/store";
|
||||
import { gameLoaded, gameUnloaded } from "./actions";
|
||||
import { NavMesh, NavMeshPoly } from "./liberationApi";
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface NavMeshState {
|
||||
blue: NavMeshPoly[];
|
||||
red: NavMeshPoly[];
|
||||
}
|
||||
|
||||
const initialState: NavMeshState = {
|
||||
blue: [],
|
||||
red: [],
|
||||
};
|
||||
|
||||
interface INavMeshUpdate {
|
||||
blue: boolean;
|
||||
mesh: NavMesh;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(gameLoaded, (state, action) => {
|
||||
state.blue = action.payload.navmeshes.blue.polys;
|
||||
state.red = action.payload.navmeshes.red.polys;
|
||||
});
|
||||
builder.addCase(gameUnloaded, (state) => {
|
||||
state.blue = [];
|
||||
state.red = [];
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const { updated: navMeshUpdated } = navMeshSlice.actions;
|
||||
|
||||
export const selectNavMeshes = (state: RootState) => state.navmeshes;
|
||||
|
||||
export default navMeshSlice.reducer;
|
||||
Reference in New Issue
Block a user