+ data-coalition=${this.#options.coalition}
+ data-pilot=${this.#options.human? "human": "ai"}>
-
${this.#name}
+
${this.#options.name}
@@ -68,7 +53,7 @@ export class UnitMarker extends L.Marker {
-
${this.#unitName}
+
${this.#options.unitName}
@@ -87,14 +72,14 @@ export class UnitMarker extends L.Marker {
}
draw(data: MarkerData) {
- this.#alive = data.alive;
+ this.#data;
var element = this.getElement();
-
if (element != null)
{
- element.querySelector(".unit")?.setAttribute("data-is-selected", String(this.getSelected()));
- element.querySelector(".unit-vvi-heading")?.setAttribute("style",`transform: rotate(${rad2deg(data.heading)}deg); width: ${data.speed / 5}px`);
+ element.querySelector(".unit-vvi-heading")?.setAttribute("style",`transform: rotate(${rad2deg(data.heading)}deg); width: ${15 + data.speed / 5}px`);
+ element.querySelector(".unit")?.setAttribute("data-fuel-level", "20");
+ element.querySelector(".unit")?.setAttribute("data-has-fox-1", "true");
var unitHeadingDiv = element.querySelector(".unit-heading");
if (unitHeadingDiv != null)
@@ -102,7 +87,7 @@ export class UnitMarker extends L.Marker {
var unitAltitudeDiv = element.querySelector(".unit-altitude");
if (unitAltitudeDiv != null)
- unitAltitudeDiv.innerHTML = String(Math.floor(data.altitude / 1000));
+ unitAltitudeDiv.innerHTML = String(Math.floor(data.altitude / 0.3048 / 1000));
}
var pos = getMap().latLngToLayerPoint(this.getLatLng()).round();
this.setZIndexOffset(Math.floor(data.altitude) - pos.y);
@@ -110,9 +95,7 @@ export class UnitMarker extends L.Marker {
setSelected(selected: boolean) {
this.#selected = selected;
- this.getElement()?.querySelector("#icon")?.classList.remove("ol-unit-marker-hovered");
- this.getElement()?.querySelector("#ring")?.classList.toggle("ol-unit-marker-selected", selected);
- this.getElement()?.querySelector("#background")?.classList.toggle("ol-unit-marker-selected", selected);
+ this.getElement()?.querySelector(".unit")?.setAttribute("data-is-selected", String(this.getSelected()));
}
getSelected() {
@@ -120,141 +103,46 @@ export class UnitMarker extends L.Marker {
}
setHovered(hovered: boolean) {
- this.getElement()?.querySelector("#icon")?.classList.toggle("ol-unit-marker-hovered", hovered && this.#alive);
+ this.getElement()?.querySelector("#icon")?.classList.toggle("ol-unit-marker-hovered", hovered && this.#data.alive);
}
- getName() {
- return this.#name;
+ getData() {
+ return this.#data;
}
- getHuman() {
- return this.#human;
- }
-
- getAI() {
- return this.#AI;
- }
-
- getAlive() {
- return this.#alive;
- }
-
- getVisibility() {
- return "full";
- }
-
- getUnitImage() {
- return new Image().src = "images/units/unit.png"
+ getOptions() {
+ return this.#options;
}
}
export class AirUnitMarker extends UnitMarker {
- getVisibility() {
- if (this.getAlive())
- {
- if (this.getSelected())
- return "full";
- else if (this.getHuman())
- return AirUnit.getVisibility().human;
- else if (this.getAI())
- return AirUnit.getVisibility().ai;
- else
- return AirUnit.getVisibility().uncontrolled;
- }
- else
- return "minimal";
- }
+
}
export class AircraftMarker extends AirUnitMarker {
- getUnitImage()
- {
- return new Image().src = "images/units/" + getAircrafImage(this.getName());
- }
+
}
export class HelicopterMarker extends AirUnitMarker {
- getUnitImage()
- {
- return new Image().src = "images/units/airUnit.png"
- }
+
}
export class GroundUnitMarker extends UnitMarker {
- /* Are user driven units recognized as human? */
- getVisibility() {
- if (this.getAlive())
- {
- if (this.getSelected())
- return "full";
- else if (this.getHuman())
- return GroundUnit.getVisibility().human;
- else if (this.getAI())
- return GroundUnit.getVisibility().ai;
- else
- return GroundUnit.getVisibility().uncontrolled;
- }
- else
- return "minimal";
- }
-
- getUnitImage()
- {
- return new Image().src = "images/units/groundUnit.png"
- }
+
}
export class NavyUnitMarker extends UnitMarker {
- getVisibility() {
- if (this.getAlive())
- {
- if (this.getSelected())
- return "full";
- else if (this.getHuman())
- return NavyUnit.getVisibility().human;
- else if (this.getAI())
- return NavyUnit.getVisibility().ai;
- else
- return NavyUnit.getVisibility().uncontrolled;
- }
- else
- return "minimal";
- }
-
- getUnitImage()
- {
- return new Image().src = "images/units/navyUnit.png"
- }
+
}
export class WeaponMarker extends UnitMarker {
- getVisibility() {
- if (this.getAlive())
- {
- if (this.getSelected())
- return "full";
- else if (this.getHuman())
- return Weapon.getVisibility().human;
- else if (this.getAI())
- return Weapon.getVisibility().ai;
- else
- return Weapon.getVisibility().uncontrolled;
- }
- else
- return "minimal";
- }
+
}
export class BombMarker extends WeaponMarker {
- getUnitImage()
- {
- return new Image().src = "images/units/bomb.png"
- }
+
}
export class MissileMarker extends WeaponMarker {
- getUnitImage()
- {
- return new Image().src = "images/units/missile.png"
- }
+
}
\ No newline at end of file
diff --git a/client/src/units/unitsmanager.ts b/client/src/units/unitsmanager.ts
index 4e8ca445..524d44d3 100644
--- a/client/src/units/unitsmanager.ts
+++ b/client/src/units/unitsmanager.ts
@@ -1,7 +1,7 @@
import { LatLng, LatLngBounds } from "leaflet";
import { getMap, getUnitControlPanel, getUnitInfoPanel } from "..";
import { Unit, GroundUnit } from "./unit";
-import { cloneUnit } from "../dcs/dcs";
+import { cloneUnit } from "../server/server";
export class UnitsManager {
#units: { [ID: number]: Unit };
@@ -40,19 +40,11 @@ export class UnitsManager {
return this.#units;
}
- addUnit(ID: number, data: any) {
+ addUnit(ID: number, data: UnitData) {
/* The name of the unit category is exactly the same as the constructor name */
var constructor = Unit.getConstructor(data.category);
if (constructor != undefined) {
- var options = {
- unitName: data.unitName,
- name: data.name,
- human: data.flags.Human,
- coalitionID: data.coalitionID,
- type: data.type,
- AI: data.AI
- }
- this.#units[ID] = new constructor(ID, options);
+ this.#units[ID] = new constructor(ID, data);
}
}
@@ -80,13 +72,13 @@ export class UnitsManager {
this.#units[ID]?.setSelected(true);
}
- update(data: any) {
- for (let ID in data["units"]) {
+ update(data: ServerData) {
+ for (let ID in data.units) {
/* 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]);
+ this.addUnit(parseInt(ID), data.units[ID]);
}
- this.#units[parseInt(ID)].update(data["units"][ID]);
+ this.#units[parseInt(ID)].update(data.units[ID]);
}
/* Update the unit info panel */
@@ -124,7 +116,7 @@ export class UnitsManager {
{
if (this.#units[ID].getHidden() == false)
{
- var latlng = new LatLng(this.#units[ID].latitude, this.#units[ID].longitude);
+ var latlng = new LatLng(this.#units[ID].getFlightData().latitude, this.#units[ID].getFlightData().longitude);
if (bounds.contains(latlng))
{
this.#units[ID].setSelected(true);
@@ -148,9 +140,9 @@ export class UnitsManager {
for (let idx in this.getSelectedUnits())
{
var unit = this.getSelectedUnits()[idx];
- if (unit.isLeader)
+ if (unit.getFormationData().isLeader)
leaders.push(unit);
- else if (unit.isWingman)
+ else if (unit.getFormationData().isWingman)
{
var leader = unit.getLeader();
if (leader && !leaders.includes(leader))
@@ -165,7 +157,7 @@ export class UnitsManager {
for (let idx in this.getSelectedUnits())
{
var unit = this.getSelectedUnits()[idx];
- if (!unit.isLeader && !unit.isWingman)
+ if (!unit.getFormationData().isLeader && !unit.getFormationData().isWingman)
singletons.push(unit);
}
return singletons;
@@ -290,12 +282,12 @@ export class UnitsManager {
var wingmenIDs = [];
for (let idx in selectedUnits)
{
- if (selectedUnits[idx].isWingman)
+ if (selectedUnits[idx].getFormationData().isWingman)
{
//console.log(selectedUnits[idx].unitName + " is already in a formation.");
return;
}
- else if (selectedUnits[idx].isLeader)
+ else if (selectedUnits[idx].getFormationData().isLeader)
{
//console.log(selectedUnits[idx].unitName + " is already in a formation.");
return;
diff --git a/client/views/unitcontrolpanel.ejs b/client/views/unitcontrolpanel.ejs
index c9f5dd6e..369dae65 100644
--- a/client/views/unitcontrolpanel.ejs
+++ b/client/views/unitcontrolpanel.ejs
@@ -1,14 +1,14 @@
-
+
-