More work on follow and tanking

This commit is contained in:
Pax1601
2023-04-14 17:30:10 +02:00
parent b56f1ca547
commit 39698c66a3
15 changed files with 308 additions and 104 deletions

View File

@@ -37,19 +37,21 @@ interface FormationData {
}
interface TaskData {
currentState: string;
currentTask: string;
activePath: any;
targetSpeed: number;
targetAltitude: number;
isTanker: boolean;
isAWACS: boolean;
radioOn: boolean;
TACANOn: boolean;
radioFrequency: number;
radioCallsign: number;
TACANChannel: number;
TACANXY: string;
TACANCallsign: string;
radioFrequency: number;
radioCallsign: number;
radioCallsignNumber: number;
radioAMFM: string;
}
interface OptionsData {

View File

@@ -5,12 +5,12 @@ export class UnitContextMenu extends ContextMenu {
super(id);
}
setOptions(options: string[], callback: CallableFunction)
setOptions(options: {[key: string]: string}, callback: CallableFunction)
{
this.getContainer()?.replaceChildren(...options.map((option: string) =>
this.getContainer()?.replaceChildren(...Object.keys(options).map((option: string, idx: number) =>
{
var button = document.createElement("button");
button.innerText = option;
button.innerHTML = options[option];
button.addEventListener("click", () => callback(option));
return (button);
}));

View File

@@ -18,7 +18,7 @@ export class MouseInfoPanel extends Panel {
this.#measureMarker = new Marker([0, 0], {icon: this.#measureIcon, interactive: false});
this.#measureBox = document.createElement("div");
this.#measureBox.classList.add("ol-measure-box");
this.#measureBox.classList.add("ol-measure-box", "hide");
document.body.appendChild(this.#measureBox);
getMap()?.on("click", (e: any) => this.#onMapClick(e));

View File

@@ -111,6 +111,9 @@ export class UnitControlPanel extends Panel {
update() {
var units = getUnitsManager().getSelectedUnits();
this.getElement().querySelector("#advanced-settings-div")?.classList.toggle("hide", units.length != 1);
if (this.getElement() != null && units.length > 0) {
this.#showFlightControlSliders(units);
@@ -123,8 +126,6 @@ export class UnitControlPanel extends Panel {
else
database = null; // TODO add databases for other unit types
console.log(unit.getBaseData());
var button = document.createElement("button");
var callsign = unit.getBaseData().unitName || "";
@@ -202,19 +203,20 @@ export class UnitControlPanel extends Panel {
#updateAdvancedSettingsDialog(units: Unit[])
{
this.getElement().querySelector("#advanced-settings-div")?.classList.toggle("hide", units.length != 1);
if (units.length == 1)
{
const unit = units[0];
(<HTMLElement>this.#advancedSettingsDialog.querySelector("#unit-name")).innerText = unit.getBaseData().unitName;
if (getUnitsManager().getSelectedUnits().length == 1){
if (getUnitsManager().getSelectedUnits().length == 1)
{
var asd = this.#advancedSettingsDialog;
this.#radioCallsignDropdown.setOptions(["Enfield", "Springfield", "Uzi", "Colt", "Dodge", "Ford", "Chevy", "Pontiac"]);
this.#radioCallsignDropdown.selectValue(unit.getTaskData().radioCallsign);
this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.querySelector("input")?.setAttribute('checked', String(unit.getTaskData().isTanker));
this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.querySelector("input")?.setAttribute('checked', String(unit.getTaskData().isAWACS));
var tankerCheckbox = this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.querySelector("input")
if (tankerCheckbox) tankerCheckbox.checked = unit.getTaskData().isTanker;
var AWACSCheckbox = this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.querySelector("input")
if (AWACSCheckbox) AWACSCheckbox.checked = unit.getTaskData().isAWACS;
var roles = aircraftDatabase.getByName(unit.getBaseData().name)?.loadouts.map((loadout) => {return loadout.roles})
if (roles != undefined && Array.prototype.concat.apply([], roles)?.includes("Tanker")){
@@ -240,7 +242,7 @@ export class UnitControlPanel extends Panel {
#applyAdvancedSettings()
{
const isTanker = this.#advancedSettingsDialog.querySelector("#tanker-checkbox")?.querySelector("input")?.checked? true: false;
const isAWACS = false; //this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.querySelector("input")?.checked? true: false;
const isAWACS = this.#advancedSettingsDialog.querySelector("#AWACS-checkbox")?.querySelector("input")?.checked? true: false;
const TACANChannel = Number(this.#advancedSettingsDialog.querySelector("#TACAN-channel")?.querySelector("input")?.value);
const TACANXY = this.#TACANXYDropdown.getValue();
const TACANCallsign = <string> this.#advancedSettingsDialog.querySelector("#tacan-callsign")?.querySelector("input")?.value

View File

@@ -117,6 +117,12 @@ export function attackUnit(ID: number, targetID: number) {
POST(data, () => { });
}
export function followUnit(ID: number, targetID: number) {
var command = { "ID": ID, "targetID": targetID };
var data = { "followUnit": command }
POST(data, () => { });
}
export function cloneUnit(ID: number, latlng: L.LatLng) {
var command = { "ID": ID, "location": latlng };
var data = { "cloneUnit": command }

View File

@@ -1,7 +1,7 @@
import { Marker, LatLng, Polyline, Icon, DivIcon } from 'leaflet';
import { getMap, getUnitsManager } from '..';
import { rad2deg } from '../other/utils';
import { addDestination, attackUnit, changeAltitude, changeSpeed, createFormation as setLeader, deleteUnit, getUnits, landAt, setAltitude, setReactionToThreat, setROE, setSpeed, refuel, setAdvacedOptions } from '../server/server';
import { addDestination, attackUnit, changeAltitude, changeSpeed, createFormation as setLeader, deleteUnit, getUnits, landAt, setAltitude, setReactionToThreat, setROE, setSpeed, refuel, setAdvacedOptions, followUnit } from '../server/server';
import { aircraftDatabase } from './aircraftdatabase';
import { groundUnitsDatabase } from './groundunitsdatabase';
@@ -46,19 +46,21 @@ export class Unit extends Marker {
wingmenIDs: [],
},
taskData: {
currentState: "IDLE",
currentTask: "",
activePath: {},
targetSpeed: 0,
targetAltitude: 0,
isTanker: false,
isAWACS: false,
radioOn: false,
TACANOn: false,
radioFrequency: 0,
radioCallsign: 0,
TACANChannel: 0,
TACANXY: "X",
TACANCallsign: "",
radioFrequency: 0,
radioCallsign: 0,
radioCallsignNumber: 0,
radioAMFM: "AM"
},
optionsData: {
ROE: "",
@@ -336,6 +338,16 @@ export class Unit extends Marker {
}
}
followUnit(targetID: number) {
/* Call DCS attackUnit function */
if (this.ID != targetID) {
followUnit(this.ID, targetID);
}
else {
// TODO: show a message
}
}
landAt(latlng: LatLng) {
landAt(this.ID, latlng);
}
@@ -400,22 +412,23 @@ export class Unit extends Marker {
}
#onContextMenu(e: any) {
var options: string[] = [];
var options: {[key: string]: string} = {};
if (getUnitsManager().getSelectedUnits().length > 0 && !(getUnitsManager().getSelectedUnits().includes(this)))
{
options = [
'Attack'
]
options = {
'Attack': `<div id="attack">Attack</div>`,
'Follow': `<div id="follow">Follow</div>`
}
}
else if (getUnitsManager().getSelectedUnits().length > 0 && (getUnitsManager().getSelectedUnits().includes(this)))
else if ((getUnitsManager().getSelectedUnits().length > 0 && (getUnitsManager().getSelectedUnits().includes(this))) || getUnitsManager().getSelectedUnits().length == 0)
{
if (this.getBaseData().category == "Aircraft")
{
options.push("Refuel"); // TODO Add some way of knowing which aircraft can AAR
options["Refuel"] = `<div id="refuel">Refuel</div>`; // TODO Add some way of knowing which aircraft can AAR
}
}
if (options.length > 0)
if (Object.keys(options).length > 0)
{
getMap().showUnitContextMenu(e);
getMap().getUnitContextMenu().setOptions(options, (option: string) => {
@@ -430,6 +443,8 @@ export class Unit extends Marker {
getUnitsManager().selectedUnitsAttackUnit(this.ID);
if (action === "Refuel")
getUnitsManager().selectedUnitsRefuel();
if (action === "Follow")
getUnitsManager().selectedUnitsFollowUnit(this.ID);
}
#updateMarker() {

View File

@@ -334,6 +334,14 @@ export class UnitsManager {
}
}
selectedUnitsFollowUnit(ID: number) {
var selectedUnits = this.getSelectedUnits();
for (let idx in selectedUnits) {
var commandedUnit = selectedUnits[idx];
commandedUnit.followUnit(ID);
}
}
copyUnits()
{
this.#copiedUnits = this.getSelectedUnits();
@@ -370,7 +378,7 @@ export class UnitsManager {
setTimeout(() => {
document.dispatchEvent(new CustomEvent("unitsSelection", {detail: this.getSelectedUnits()}));
this.#selectionEventDisabled = false;
}, 300);
}, 100);
this.#selectionEventDisabled = true;
}
}