mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added back attack and movement functions, missionData is now part of units
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { setActiveCoalition } from "..";
|
||||
import { getActiveCoalition, setActiveCoalition } from "..";
|
||||
import { deg2rad } from "../other/utils";
|
||||
|
||||
export class SelectionWheel
|
||||
@@ -57,6 +57,22 @@ export class SelectionWheel
|
||||
}
|
||||
button.appendChild(image);
|
||||
}
|
||||
|
||||
/* Hide the coalition switch if required */
|
||||
var switchContainer = <HTMLElement> this.#container.querySelector("#coalition-switch-container");
|
||||
if (showCoalition == false)
|
||||
{
|
||||
switchContainer.style.display = "none";
|
||||
document.documentElement.style.setProperty('--active-coalition-color', getComputedStyle(this.#container).getPropertyValue("--neutral-coalition-color"));
|
||||
}
|
||||
else
|
||||
{
|
||||
switchContainer.style.display = "block";
|
||||
if (getActiveCoalition() == "blue")
|
||||
document.documentElement.style.setProperty('--active-coalition-color', getComputedStyle(this.#container).getPropertyValue("--blue-coalition-color"));
|
||||
else
|
||||
document.documentElement.style.setProperty('--active-coalition-color', getComputedStyle(this.#container).getPropertyValue("--red-coalition-color"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as L from 'leaflet'
|
||||
import { getUnitsManager } from '..';
|
||||
import { ConvertDDToDMS } from '../other/utils';
|
||||
|
||||
/* Edit here to change server address */
|
||||
@@ -24,7 +25,6 @@ export function getDataFromDCS(callback: CallableFunction)
|
||||
|
||||
export function addDestination(ID: number, path: any)
|
||||
{
|
||||
// TODO move in dedicated file
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("PUT", RESTaddress);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
@@ -89,34 +89,34 @@ export function spawnAircraft(type: string, latlng: L.LatLng, coalition: string,
|
||||
|
||||
export function attackUnit(ID: number, targetID: number)
|
||||
{
|
||||
//var xhr = new XMLHttpRequest();
|
||||
//xhr.open("PUT", RESTaddress);
|
||||
//xhr.setRequestHeader("Content-Type", "application/json");
|
||||
//xhr.onreadystatechange = () => {
|
||||
// if (xhr.readyState === 4) {
|
||||
// console.log("Unit " + unitsManager.getUnitByID(ID).unitName + " attack " + unitsManager.getUnitByID(targetID).unitName );
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//var command = {"ID": ID, "targetID": targetID};
|
||||
//var data = {"attackUnit": command}
|
||||
//
|
||||
//xhr.send(JSON.stringify(data));
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("PUT", RESTaddress);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
console.log("Unit " + getUnitsManager().getUnitByID(ID).unitName + " attack " + getUnitsManager().getUnitByID(targetID).unitName );
|
||||
}
|
||||
};
|
||||
|
||||
var command = {"ID": ID, "targetID": targetID};
|
||||
var data = {"attackUnit": command}
|
||||
|
||||
xhr.send(JSON.stringify(data));
|
||||
}
|
||||
|
||||
export function cloneUnit(ID: number)
|
||||
{
|
||||
//var xhr = new XMLHttpRequest();
|
||||
//xhr.open("PUT", RESTaddress);
|
||||
//xhr.setRequestHeader("Content-Type", "application/json");
|
||||
//xhr.onreadystatechange = () => {
|
||||
// if (xhr.readyState === 4) {
|
||||
// console.log("Unit " + unitsManager.getUnitByID(ID).unitName + " cloned");
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//var command = {"ID": ID};
|
||||
//var data = {"cloneUnit": command}
|
||||
//
|
||||
//xhr.send(JSON.stringify(data));
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("PUT", RESTaddress);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
console.log("Unit " + getUnitsManager().getUnitByID(ID).unitName + " cloned");
|
||||
}
|
||||
};
|
||||
|
||||
var command = {"ID": ID};
|
||||
var data = {"cloneUnit": command}
|
||||
|
||||
xhr.send(JSON.stringify(data));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ function setup()
|
||||
scenarioDropdown = new Dropdown("scenario-dropdown", ["Caucasus", "Syria", "Nevada", "Marianas", "South Atlantic", "The channel"], () => {});
|
||||
mapSourceDropdown = new Dropdown("map-source-dropdown", map.getLayers(), (option: string) => map.setLayer(option));
|
||||
|
||||
activeCoalition = "blue";
|
||||
|
||||
/* Main update rate = 250ms is minimum time, equal to server update time. */
|
||||
setInterval(() => getDataFromDCS(update), 250);
|
||||
}
|
||||
|
||||
@@ -158,9 +158,9 @@ export class Map extends L.Map
|
||||
{
|
||||
if (!e.originalEvent.ctrlKey)
|
||||
{
|
||||
//unitsManager.clearDestinations();
|
||||
getUnitsManager().clearDestinations();
|
||||
}
|
||||
//unitsManager.addDestination(e.latlng)
|
||||
getUnitsManager().addDestination(e.latlng)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ import { Marker, LatLng, Polyline } from 'leaflet';
|
||||
import { ConvertDDToDMS } from '../other/utils';
|
||||
import { getMap, getUnitsManager } from '..';
|
||||
import { UnitMarker, MarkerOptions } from './unitmarker';
|
||||
import { addDestination } from '../dcs/dcs';
|
||||
//import { attackUnit } from 'DCS/DCSCommands.js'
|
||||
import { addDestination, attackUnit } from '../dcs/dcs';
|
||||
|
||||
export class Unit
|
||||
{
|
||||
@@ -86,7 +85,7 @@ export class Unit
|
||||
/* The marker is set by the inherited class */
|
||||
this.#marker = marker;
|
||||
this.#marker.on('click', (e) => this.#onClick(e));
|
||||
//this.#marker.on('dblclick', (e) => this.#onDoubleClick(e));
|
||||
this.#marker.on('dblclick', (e) => this.#onDoubleClick(e));
|
||||
|
||||
this.#selected = false;
|
||||
this.#preventClick = false;
|
||||
@@ -142,7 +141,7 @@ export class Unit
|
||||
|
||||
setSelected(selected: boolean)
|
||||
{
|
||||
// Only alive units can be selected. Some units are not selectable (weapons)
|
||||
/* Only alive units can be selected. Some units are not selectable (weapons) */
|
||||
if ((this.alive || !selected) && this.#selectable && this.#selected != selected)
|
||||
{
|
||||
this.#selected = selected;
|
||||
@@ -168,7 +167,7 @@ export class Unit
|
||||
{
|
||||
path = {"1": latlng};
|
||||
}
|
||||
addDestination
|
||||
addDestination(this.ID, path);
|
||||
}
|
||||
|
||||
clearDestinations()
|
||||
@@ -193,6 +192,25 @@ export class Unit
|
||||
}, 200);
|
||||
}
|
||||
|
||||
#onDoubleClick(e: any)
|
||||
{
|
||||
clearTimeout(this.#timer);
|
||||
this.#preventClick = true;
|
||||
|
||||
var options = [
|
||||
{'tooltip': 'Attack', 'src': 'attack.png', 'callback': () => {getMap().hideSelectionWheel(); getUnitsManager().attackUnit(this.ID);}},
|
||||
{'tooltip': 'Go to tanker', 'src': 'tanker.png', 'callback': () => {getMap().hideSelectionWheel(); /*showMessage("Function not implemented yet");*/}},
|
||||
{'tooltip': 'RTB', 'src': 'rtb.png', 'callback': () => {getMap().hideSelectionWheel(); /*showMessage("Function not implemented yet");*/}}
|
||||
]
|
||||
|
||||
if (!this.leader && !this.wingman)
|
||||
{
|
||||
options.push({'tooltip': 'Create formation', 'src': 'formation.png', 'callback': () => {getMap().hideSelectionWheel(); /*unitsManager.createFormation(this.ID);*/}});
|
||||
}
|
||||
|
||||
getMap().showSelectionWheel(e.originalEvent, options, false);
|
||||
}
|
||||
|
||||
#updateMarker()
|
||||
{
|
||||
/* Add the marker if not present */
|
||||
@@ -217,21 +235,21 @@ export class Unit
|
||||
var _points = [];
|
||||
_points.push(new LatLng(this.latitude, this.longitude));
|
||||
|
||||
// Add markers if missing
|
||||
/* Add markers if missing */
|
||||
while (this.#pathMarkers.length < Object.keys(this.activePath).length)
|
||||
{
|
||||
var marker = new Marker([0, 0]).addTo(getMap());
|
||||
this.#pathMarkers.push(marker);
|
||||
}
|
||||
|
||||
// Remove markers if too many
|
||||
/* Remove markers if too many */
|
||||
while (this.#pathMarkers.length > Object.keys(this.activePath).length)
|
||||
{
|
||||
getMap().removeLayer(this.#pathMarkers[this.#pathMarkers.length - 1]);
|
||||
this.#pathMarkers.splice(this.#pathMarkers.length - 1, 1)
|
||||
}
|
||||
|
||||
// Update the position of the existing markers (to avoid creating markers uselessly)
|
||||
/* Update the position of the existing markers (to avoid creating markers uselessly) */
|
||||
for (let WP in this.activePath)
|
||||
{
|
||||
var destination = this.activePath[WP];
|
||||
@@ -252,69 +270,7 @@ export class Unit
|
||||
this.#pathPolyline.setLatLngs([]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
#onDoubleClick(e)
|
||||
{
|
||||
clearTimeout(this.#timer);
|
||||
this.#preventClick = true;
|
||||
|
||||
var options = [
|
||||
{'tooltip': 'Attack', 'src': 'attack.png', 'callback': () => {map.removeSelectionWheel(); unitsManager.attackUnit(this.ID);}},
|
||||
{'tooltip': 'Go to tanker', 'src': 'tanker.png', 'callback': () => {map.removeSelectionWheel(); showMessage("Function not implemented yet");}},
|
||||
{'tooltip': 'RTB', 'src': 'rtb.png', 'callback': () => {map.removeSelectionWheel(); showMessage("Function not implemented yet");}}
|
||||
]
|
||||
|
||||
if (!this.leader && !this.wingman)
|
||||
{
|
||||
options.push({'tooltip': 'Create formation', 'src': 'formation.png', 'callback': () => {map.removeSelectionWheel(); unitsManager.createFormation(this.ID);}});
|
||||
}
|
||||
|
||||
map.showSelectionWheel(e, options, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
drawPath()
|
||||
{
|
||||
var _points = [];
|
||||
_points.push(new LatLng(this.latitude, this.longitude));
|
||||
|
||||
// Add markers if missing
|
||||
while (this.#pathMarkers.length < Object.keys(this.activePath).length)
|
||||
{
|
||||
var marker = new Marker([0, 0]).addTo(map.getMap());
|
||||
this.#pathMarkers.push(marker);
|
||||
}
|
||||
|
||||
// Remove markers if too many
|
||||
while (this.#pathMarkers.length > Object.keys(this.activePath).length)
|
||||
{
|
||||
map.getMap().removeLayer(this.#pathMarkers[this.#pathMarkers.length - 1]);
|
||||
this.#pathMarkers.splice(this.#pathMarkers.length - 1, 1)
|
||||
}
|
||||
|
||||
// Update the position of the existing markers (to avoid creating markers uselessly)
|
||||
for (let WP in this.activePath)
|
||||
{
|
||||
var destination = this.activePath[WP];
|
||||
this.#pathMarkers[parseInt(WP) - 1].setLatLng([destination.lat, destination.lng]);
|
||||
_points.push(new LatLng(destination.lat, destination.lng));
|
||||
this.#pathPolyline.setLatLngs(_points);
|
||||
}
|
||||
}
|
||||
|
||||
clearPath()
|
||||
{
|
||||
for (let WP in this.#pathMarkers)
|
||||
{
|
||||
map.getMap().removeLayer(this.#pathMarkers[WP]);
|
||||
}
|
||||
this.#pathMarkers = [];
|
||||
this.#pathPolyline.setLatLngs([]);
|
||||
}
|
||||
|
||||
drawTargets()
|
||||
{
|
||||
for (let typeIndex in this.missionData['targets'])
|
||||
@@ -359,8 +315,9 @@ export class Unit
|
||||
map.getMap().removeLayer(this.#targetsPolylines[index])
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
attackUnit(targetID)
|
||||
attackUnit(targetID: number)
|
||||
{
|
||||
// Call DCS attackUnit function
|
||||
if (this.ID != targetID)
|
||||
@@ -373,6 +330,7 @@ export class Unit
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
changeSpeed(speedChange)
|
||||
{
|
||||
// TODO move in dedicated file
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getUnitInfoPanel } from "..";
|
||||
import { getMap, getUnitInfoPanel } from "..";
|
||||
import { Unit, GroundUnit } from "./unit";
|
||||
|
||||
export class UnitsManager
|
||||
@@ -14,7 +14,7 @@ export class UnitsManager
|
||||
|
||||
addUnit(ID: number, data: any)
|
||||
{
|
||||
// The name of the unit category is exactly the same as the constructor name
|
||||
/* The name of the unit category is exactly the same as the constructor name */
|
||||
var constructor = Unit.getConstructor(data.category);
|
||||
if (constructor != undefined)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ export class UnitsManager
|
||||
{
|
||||
for (let ID in data["units"])
|
||||
{
|
||||
// Create the unit if missing from the local array, then update the data. Drawing is handled by leaflet.
|
||||
/* Create the unit if missing from the local array, then update the data. Drawing is handled by leaflet. */
|
||||
if (!(ID in this.#units))
|
||||
{
|
||||
this.addUnit(parseInt(ID), data["units"][ID]);
|
||||
@@ -72,16 +72,16 @@ export class UnitsManager
|
||||
|
||||
onUnitSelection()
|
||||
{
|
||||
//if (this.getSelectedUnits().length > 0)
|
||||
//{
|
||||
// map.setState("MOVE_UNIT");
|
||||
// unitControlPanel.setEnabled(true);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// map.setState("IDLE");
|
||||
// unitControlPanel.setEnabled(false);
|
||||
//}
|
||||
if (this.getSelectedUnits().length > 0)
|
||||
{
|
||||
getMap().setState("MOVE_UNIT");
|
||||
//unitControlPanel.setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
getMap().setState("IDLE");
|
||||
//unitControlPanel.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// selectFromBounds(bounds)
|
||||
@@ -110,33 +110,33 @@ export class UnitsManager
|
||||
return selectedUnits;
|
||||
}
|
||||
|
||||
// addDestination(latlng)
|
||||
// {
|
||||
// var selectedUnits = this.getSelectedUnits();
|
||||
// for (let idx in selectedUnits)
|
||||
// {
|
||||
// var commandedUnit = selectedUnits[idx];
|
||||
// if (selectedUnits[idx].wingman)
|
||||
// {
|
||||
// commandedUnit = this.getLeader(selectedUnits[idx].ID);
|
||||
// }
|
||||
// commandedUnit.addDestination(latlng);
|
||||
// }
|
||||
// }
|
||||
addDestination(latlng: L.LatLng)
|
||||
{
|
||||
var selectedUnits = this.getSelectedUnits();
|
||||
for (let idx in selectedUnits)
|
||||
{
|
||||
var commandedUnit = selectedUnits[idx];
|
||||
//if (selectedUnits[idx].wingman)
|
||||
//{
|
||||
// commandedUnit = this.getLeader(selectedUnits[idx].ID);
|
||||
//}
|
||||
commandedUnit.addDestination(latlng);
|
||||
}
|
||||
}
|
||||
|
||||
// clearDestinations()
|
||||
// {
|
||||
// var selectedUnits = this.getSelectedUnits();
|
||||
// for (let idx in selectedUnits)
|
||||
// {
|
||||
// var commandedUnit = selectedUnits[idx];
|
||||
// if (selectedUnits[idx].wingman)
|
||||
// {
|
||||
// commandedUnit = this.getLeader(selectedUnits[idx].ID);
|
||||
// }
|
||||
// commandedUnit.clearDestinations();
|
||||
// }
|
||||
// }
|
||||
clearDestinations()
|
||||
{
|
||||
var selectedUnits = this.getSelectedUnits();
|
||||
for (let idx in selectedUnits)
|
||||
{
|
||||
var commandedUnit = selectedUnits[idx];
|
||||
//if (selectedUnits[idx].wingman)
|
||||
//{
|
||||
// commandedUnit = this.getLeader(selectedUnits[idx].ID);
|
||||
//}
|
||||
commandedUnit.clearDestinations();
|
||||
}
|
||||
}
|
||||
|
||||
// selectedUnitsMove()
|
||||
// {
|
||||
@@ -187,20 +187,20 @@ export class UnitsManager
|
||||
// }
|
||||
// }
|
||||
|
||||
// attackUnit(ID)
|
||||
// {
|
||||
// var selectedUnits = this.getSelectedUnits();
|
||||
// for (let idx in selectedUnits)
|
||||
// {
|
||||
// // If a unit is a wingman, send the command to its leader
|
||||
// var commandedUnit = selectedUnits[idx];
|
||||
// if (selectedUnits[idx].wingman)
|
||||
// {
|
||||
// commandedUnit = this.getLeader(selectedUnits[idx].ID);
|
||||
// }
|
||||
// commandedUnit.attackUnit(ID);
|
||||
// }
|
||||
// }
|
||||
attackUnit(ID: number)
|
||||
{
|
||||
var selectedUnits = this.getSelectedUnits();
|
||||
for (let idx in selectedUnits)
|
||||
{
|
||||
/* If a unit is a wingman, send the command to its leader */
|
||||
var commandedUnit = selectedUnits[idx];
|
||||
//if (selectedUnits[idx].wingman)
|
||||
//{
|
||||
// commandedUnit = this.getLeader(selectedUnits[idx].ID);
|
||||
//}
|
||||
commandedUnit.attackUnit(ID);
|
||||
}
|
||||
}
|
||||
|
||||
// createFormation(ID)
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user