Added states and more work on custom formations

This commit is contained in:
Pax1601
2023-04-18 11:01:31 +02:00
parent be69aeb69e
commit cfd98e74ea
19 changed files with 638 additions and 248 deletions

View File

@@ -11,6 +11,18 @@ export class UnitContextMenu extends ContextMenu {
if (dialog)
{
dialog.classList.add("hide");
var clock = 1;
while (clock < 8)
{
if ((<HTMLInputElement> dialog.querySelector(`#formation-${clock}`)).checked)
break
clock++;
}
var angleDeg = 360 - (clock - 1) * 45;
var distance = parseInt((<HTMLInputElement> dialog.querySelector(`#distance`)?.querySelector("input")).value);
var upDown = parseInt((<HTMLInputElement> dialog.querySelector(`#up-down`)?.querySelector("input")).value);
var asd= 1;
}
if (this.#callback)

View File

@@ -117,12 +117,12 @@ export function attackUnit(ID: number, targetID: number) {
POST(data, () => { });
}
export function followUnit(ID: number, targetID: number) {
export function followUnit(ID: number, targetID: number, offset: {"x": number, "y": number, "z": number}) {
// X: front-rear, positive front
// Y: top-bottom, positive bottom
// Z: left-right, positive right
var command = { "ID": ID, "targetID": targetID, "offsetX": -50, "offsetY": -10, "offsetZ": 50};
var command = { "ID": ID, "targetID": targetID, "offsetX": offset["x"], "offsetY": offset["y"], "offsetZ": offset["z"]};
var data = { "followUnit": command }
POST(data, () => { });
}

View File

@@ -330,7 +330,6 @@ export class Unit extends Marker {
}
attackUnit(targetID: number) {
/* Call DCS attackUnit function */
if (this.ID != targetID) {
attackUnit(this.ID, targetID);
}
@@ -339,10 +338,9 @@ export class Unit extends Marker {
}
}
followUnit(targetID: number) {
/* Call DCS attackUnit function */
followUnit(targetID: number, offset: {"x": number, "y": number, "z": number}) {
if (this.ID != targetID) {
followUnit(this.ID, targetID);
followUnit(this.ID, targetID, offset);
}
else {
// TODO: show a message
@@ -458,9 +456,10 @@ export class Unit extends Marker {
options = {
'Trail': `<div id="trail">Trail</div>`,
'Echelon (LH)': `<div id="echelon-lh">Echelon (LH)</div>`,
'Echelon (RH)': `<div id="echelon-rh">Echelon (RH)</div>`,
'Line abreast': `<div id="line-abreast">Line abreast</div>`,
'Echelon (LH)': `<div id="echelon-lh">Echelon (left)</div>`,
'Echelon (RH)': `<div id="echelon-rh">Echelon (right)</div>`,
'Line abreast (LH)': `<div id="line-abreast">Line abreast (left)</div>`,
'Line abreast (RH)': `<div id="line-abreast">Line abreast (right)</div>`,
'Front': `<div id="front">In front</div>`,
'Custom': `<div id="custom">Custom</div>`
}
@@ -479,7 +478,36 @@ export class Unit extends Marker {
document.getElementById("custom-formation-dialog")?.classList.remove("hide");
}
else {
getUnitsManager().selectedUnitsFollowUnit(this.ID);
// X: front-rear, positive front
// Y: top-bottom, positive top
// Z: left-right, positive right
var offset = {"x": 0, "y": 0, "z": 0};
if (action == "Trail")
{
offset.x = -50; offset.y = -30; offset.z = 0;
}
else if (action == "Echelon (LH)")
{
offset.x = -50; offset.y = -10; offset.z = -50;
}
else if (action == "Echelon (RH)")
{
offset.x = -50; offset.y = -10; offset.z = 50;
}
else if (action == "Line abreast (RH)")
{
offset.x = 0; offset.y = 0; offset.z = 50;
}
else if (action == "Line abreast (LH)")
{
offset.x = 0; offset.y = 0; offset.z = -50;
}
else if (action == "Front")
{
offset.x = 100; offset.y = 0; offset.z = 0;
}
getUnitsManager().selectedUnitsFollowUnit(this.ID, offset);
}
}
@@ -499,6 +527,8 @@ export class Unit extends Marker {
element.querySelector(".unit")?.toggleAttribute("data-is-dead", !this.getBaseData().alive);
element.querySelector(".unit")?.setAttribute("data-state", this.getTaskData().currentState.toLowerCase());
var unitHeadingDiv = element.querySelector(".unit-heading");
if (unitHeadingDiv != null)
unitHeadingDiv.innerHTML = String(Math.floor(rad2deg(this.getFlightData().heading)));
@@ -609,10 +639,10 @@ export class Aircraft extends AirUnit {
getMarkerHTML()
{
return `<div class="unit" data-object="unit-aircraft" data-status="" data-coalition="${this.getMissionData().coalition}">
return `<div class="unit" data-object="unit-aircraft" data-coalition="${this.getMissionData().coalition}">
<div class="unit-selected-spotlight"></div>
<div class="unit-marker-border"></div>
<div class="unit-status"></div>
<div class="unit-state"></div>
<div class="unit-vvi" data-rotate-to-heading></div>
<div class="unit-hotgroup">
<div class="unit-hotgroup-id"></div>

View File

@@ -334,11 +334,13 @@ export class UnitsManager {
}
}
selectedUnitsFollowUnit(ID: number) {
selectedUnitsFollowUnit(ID: number, offset: {"x": number, "y": number, "z": number}) {
var selectedUnits = this.getSelectedUnits();
var count = 1;
for (let idx in selectedUnits) {
var commandedUnit = selectedUnits[idx];
commandedUnit.followUnit(ID);
commandedUnit.followUnit(ID, {"x": offset.x * count, "y": offset.y * count, "z": offset.z * count} );
count++;
}
}