mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
fix: Laser and infrared correctly removed
This commit is contained in:
@@ -89,7 +89,7 @@ export interface BullseyesData {
|
||||
|
||||
export interface SpotsData {
|
||||
spots: {
|
||||
[key: string]: { type: string; targetPosition: { lat: number; lng: number }; sourceUnitID: number; code?: number };
|
||||
[key: string]: { active: boolean; type: string; targetPosition: { lat: number; lng: number }; sourceUnitID: number; code?: number };
|
||||
};
|
||||
sessionHash: string;
|
||||
time: number;
|
||||
|
||||
@@ -6,13 +6,20 @@ import { BLUE_COMMANDER, GAME_MASTER, NONE, RED_COMMANDER } from "../constants/c
|
||||
import { AirbasesData, BullseyesData, CommandModeOptions, DateAndTime, MissionData, SpotsData } from "../interfaces";
|
||||
import { Coalition } from "../types/types";
|
||||
import { Carrier } from "./carrier";
|
||||
import { AirbaseSelectedEvent, AppStateChangedEvent, BullseyesDataChangedEvent, CommandModeOptionsChangedEvent, EnabledCommandModesChangedEvent, MissionDataChangedEvent } from "../events";
|
||||
import {
|
||||
AirbaseSelectedEvent,
|
||||
AppStateChangedEvent,
|
||||
BullseyesDataChangedEvent,
|
||||
CommandModeOptionsChangedEvent,
|
||||
EnabledCommandModesChangedEvent,
|
||||
MissionDataChangedEvent,
|
||||
} from "../events";
|
||||
import { Spot } from "./spot";
|
||||
|
||||
/** The MissionManager */
|
||||
export class MissionManager {
|
||||
#bullseyes: { [name: string]: Bullseye } = {};
|
||||
#spots: {[key: string]: Spot} = {};
|
||||
#spots: { [key: string]: Spot } = {};
|
||||
#airbases: { [name: string]: Airbase | Carrier } = {};
|
||||
#theatre: string = "";
|
||||
#dateAndTime: DateAndTime = {
|
||||
@@ -39,7 +46,7 @@ export class MissionManager {
|
||||
constructor() {
|
||||
AppStateChangedEvent.on((state, subState) => {
|
||||
if (this.getSelectedAirbase() !== null) AirbaseSelectedEvent.dispatch(null);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/** Update location of bullseyes
|
||||
@@ -63,7 +70,7 @@ export class MissionManager {
|
||||
this.#bullseyes[idx].setCoalition(bullseye.coalition);
|
||||
}
|
||||
|
||||
BullseyesDataChangedEvent.dispatch(this.#bullseyes)
|
||||
BullseyesDataChangedEvent.dispatch(this.#bullseyes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,18 +79,18 @@ export class MissionManager {
|
||||
const spotID = Number(idx);
|
||||
const spot = data.spots[idx];
|
||||
if (this.#spots[spotID] === undefined) {
|
||||
this.#spots[spotID] = new Spot(spotID, spot.type, new LatLng(spot.targetPosition.lat, spot.targetPosition.lng), spot.sourceUnitID, spot.code);
|
||||
this.#spots[spotID] = new Spot(
|
||||
spotID,
|
||||
spot.type,
|
||||
new LatLng(spot.targetPosition.lat, spot.targetPosition.lng),
|
||||
spot.sourceUnitID,
|
||||
spot.active,
|
||||
spot.code
|
||||
);
|
||||
} else {
|
||||
if (spot.type === "laser")
|
||||
this.#spots[spotID].setCode(spot.code ?? 0)
|
||||
this.#spots[spotID].setTargetPosition( new LatLng(spot.targetPosition.lat, spot.targetPosition.lng));
|
||||
}
|
||||
}
|
||||
|
||||
/* Iterate the existing spots and remove all spots that where deleted */
|
||||
for (let idx in this.#spots) {
|
||||
if (data.spots[idx] === undefined) {
|
||||
delete this.#spots[idx];
|
||||
if (spot.type === "laser") this.#spots[spotID].setCode(spot.code ?? 0);
|
||||
this.#spots[spotID].setActive(spot.active);
|
||||
this.#spots[spotID].setTargetPosition(new LatLng(spot.targetPosition.lat, spot.targetPosition.lng));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,7 +106,7 @@ export class MissionManager {
|
||||
updateAirbases(data: AirbasesData) {
|
||||
for (let idx in data.airbases) {
|
||||
var airbase = data.airbases[idx];
|
||||
var airbaseCallsign = airbase.callsign !== ""? airbase.callsign: `carrier-${airbase.unitId}`
|
||||
var airbaseCallsign = airbase.callsign !== "" ? airbase.callsign : `carrier-${airbase.unitId}`;
|
||||
if (this.#airbases[airbaseCallsign] === undefined) {
|
||||
if (airbase.callsign != "") {
|
||||
this.#airbases[airbaseCallsign] = new Airbase({
|
||||
@@ -161,7 +168,7 @@ export class MissionManager {
|
||||
return this.#airbases;
|
||||
}
|
||||
|
||||
getSpots() {
|
||||
getSpots() {
|
||||
return this.#spots;
|
||||
}
|
||||
|
||||
@@ -279,7 +286,7 @@ export class MissionManager {
|
||||
commandModeOptions.spawnPoints.red !== this.getCommandModeOptions().spawnPoints.red ||
|
||||
commandModeOptions.spawnPoints.blue !== this.getCommandModeOptions().spawnPoints.blue ||
|
||||
commandModeOptions.restrictSpawns !== this.getCommandModeOptions().restrictSpawns ||
|
||||
commandModeOptions.restrictToCoalition !== this.getCommandModeOptions().restrictToCoalition ||
|
||||
commandModeOptions.restrictToCoalition !== this.getCommandModeOptions().restrictToCoalition ||
|
||||
commandModeOptions.setupTime !== this.getCommandModeOptions().setupTime;
|
||||
|
||||
this.#commandModeOptions = commandModeOptions;
|
||||
|
||||
@@ -2,47 +2,57 @@ import { LatLng } from "leaflet";
|
||||
import { getApp } from "../olympusapp";
|
||||
|
||||
export class Spot {
|
||||
private ID: number;
|
||||
private type: string;
|
||||
private targetPosition: LatLng;
|
||||
private sourceUnitID: number;
|
||||
private code?: number;
|
||||
#ID: number;
|
||||
#type: string;
|
||||
#targetPosition: LatLng;
|
||||
#sourceUnitID: number;
|
||||
#active: boolean;
|
||||
#code?: number;
|
||||
|
||||
constructor(ID: number, type: string, targetPosition: LatLng, sourceUnitID: number, code?: number) {
|
||||
this.ID = ID;
|
||||
this.type = type;
|
||||
this.targetPosition = targetPosition;
|
||||
this.sourceUnitID = sourceUnitID;
|
||||
this.code = code;
|
||||
constructor(ID: number, type: string, targetPosition: LatLng, sourceUnitID: number, active: boolean, code?: number) {
|
||||
this.#ID = ID;
|
||||
this.#type = type;
|
||||
this.#targetPosition = targetPosition;
|
||||
this.#sourceUnitID = sourceUnitID;
|
||||
this.#code = code;
|
||||
this.#active = active;
|
||||
}
|
||||
|
||||
// Getter methods
|
||||
getID() {
|
||||
return this.ID;
|
||||
return this.#ID;
|
||||
}
|
||||
|
||||
getType() {
|
||||
return this.type;
|
||||
return this.#type;
|
||||
}
|
||||
|
||||
getTargetPosition() {
|
||||
return this.targetPosition;
|
||||
return this.#targetPosition;
|
||||
}
|
||||
|
||||
getSourceUnitID() {
|
||||
return this.sourceUnitID;
|
||||
return this.#sourceUnitID;
|
||||
}
|
||||
|
||||
getCode() {
|
||||
return this.code;
|
||||
return this.#code;
|
||||
}
|
||||
|
||||
getActive() {
|
||||
return this.#active;
|
||||
}
|
||||
|
||||
// Setter methods
|
||||
setTargetPosition(position: LatLng) {
|
||||
this.targetPosition = position;
|
||||
this.#targetPosition = position;
|
||||
}
|
||||
|
||||
setCode(code: number) {
|
||||
this.code = code;
|
||||
this.#code = code;
|
||||
}
|
||||
|
||||
setActive(active: boolean) {
|
||||
this.#active = active;
|
||||
}
|
||||
}
|
||||
@@ -1953,21 +1953,29 @@ export abstract class Unit extends CustomMarker {
|
||||
// Iterate over all spots and draw lines, edit markers, and markers
|
||||
Object.values(getApp().getMissionManager().getSpots()).forEach((spot: Spot) => {
|
||||
if (spot.getSourceUnitID() === this.ID) {
|
||||
const spotBearing = deg2rad(bearing(this.getPosition().lat, this.getPosition().lng, spot.getTargetPosition().lat, spot.getTargetPosition().lng, false));
|
||||
const spotDistance = this.getPosition().distanceTo(spot.getTargetPosition());
|
||||
const midPosition = bearingAndDistanceToLatLng(this.getPosition().lat, this.getPosition().lng, spotBearing, spotDistance / 2);
|
||||
if (spot.getActive()) {
|
||||
const spotBearing = deg2rad(
|
||||
bearing(this.getPosition().lat, this.getPosition().lng, spot.getTargetPosition().lat, spot.getTargetPosition().lng, false)
|
||||
);
|
||||
const spotDistance = this.getPosition().distanceTo(spot.getTargetPosition());
|
||||
const midPosition = bearingAndDistanceToLatLng(this.getPosition().lat, this.getPosition().lng, spotBearing, spotDistance / 2);
|
||||
|
||||
// Draw the spot line
|
||||
this.#drawSpotLine(spot, spotBearing);
|
||||
// Draw the spot line
|
||||
this.#drawSpotLine(spot, spotBearing);
|
||||
|
||||
// Draw the spot edit marker if the map is zoomed in enough
|
||||
if (getApp().getMap().getZoom() >= SPOTS_EDIT_ZOOM_TRANSITION) {
|
||||
// Draw the spot edit marker
|
||||
this.#drawSpotEditMarker(spot, midPosition, spotBearing);
|
||||
// Draw the spot edit marker if the map is zoomed in enough
|
||||
if (getApp().getMap().getZoom() >= SPOTS_EDIT_ZOOM_TRANSITION) {
|
||||
// Draw the spot edit marker
|
||||
this.#drawSpotEditMarker(spot, midPosition, spotBearing);
|
||||
}
|
||||
|
||||
// Draw the spot marker
|
||||
this.#drawSpotMarker(spot);
|
||||
} else {
|
||||
this.#spotLines[spot.getID()]?.removeFrom(getApp().getMap());
|
||||
this.#spotEditMarkers[spot.getID()]?.removeFrom(getApp().getMap());
|
||||
this.#spotMarkers[spot.getID()]?.removeFrom(getApp().getMap());
|
||||
}
|
||||
|
||||
// Draw the spot marker
|
||||
this.#drawSpotMarker(spot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user