From 4087dbde216df99d8fc8a7cbcc0dece5bf83af65 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Mon, 29 May 2023 17:09:06 +0200 Subject: [PATCH] Minor optimizations --- .../olympus/images/units/groundunit-sam.svg | 2 +- client/src/index.ts | 2 ++ client/src/map/map.ts | 5 +-- client/src/panels/unitcontrolpanel.ts | 3 +- client/src/server/server.ts | 15 +++++--- client/src/units/unit.ts | 36 ++++++++++--------- 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/client/public/themes/olympus/images/units/groundunit-sam.svg b/client/public/themes/olympus/images/units/groundunit-sam.svg index 996af35d..ffc18a40 100644 --- a/client/public/themes/olympus/images/units/groundunit-sam.svg +++ b/client/public/themes/olympus/images/units/groundunit-sam.svg @@ -1,4 +1,4 @@ - + diff --git a/client/src/index.ts b/client/src/index.ts index ac14f5c6..06f416ff 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -98,6 +98,8 @@ function readConfig(config: any) { } function setupEvents() { + window.onanimationiteration = console.log; + /* Generic clicks */ document.addEventListener("click", (ev) => { if (ev instanceof MouseEvent && ev.target instanceof HTMLElement) { diff --git a/client/src/map/map.ts b/client/src/map/map.ts index 477b8640..b4516bdd 100644 --- a/client/src/map/map.ts +++ b/client/src/map/map.ts @@ -111,8 +111,9 @@ export class Map extends L.Map { /* Pan interval */ this.#panInterval = window.setInterval(() => { - this.panBy(new L.Point(((this.#panLeft ? -1 : 0) + (this.#panRight ? 1 : 0)) * this.#deafultPanDelta, - ((this.#panUp ? -1 : 0) + (this.#panDown ? 1 : 0)) * this.#deafultPanDelta)); + if (this.#panLeft || this.#panDown || this.#panRight || this.#panLeft) + this.panBy(new L.Point(((this.#panLeft? -1 : 0) + (this.#panRight ? 1 : 0)) * this.#deafultPanDelta, + ((this.#panUp ? -1 : 0) + (this.#panDown ? 1 : 0)) * this.#deafultPanDelta)); }, 20); /* Option buttons */ diff --git a/client/src/panels/unitcontrolpanel.ts b/client/src/panels/unitcontrolpanel.ts index 4981f4fc..8a84bdf8 100644 --- a/client/src/panels/unitcontrolpanel.ts +++ b/client/src/panels/unitcontrolpanel.ts @@ -120,8 +120,9 @@ export class UnitControlPanel extends Panel { var button = document.createElement("button"); var callsign = unit.getBaseData().unitName || ""; + var label = unit.getDatabase()?.getByName(unit.getBaseData().name)?.label || unit.getBaseData().name; - button.setAttribute("data-label", unit.getBaseData().name); + button.setAttribute("data-label", label); button.setAttribute("data-callsign", callsign); button.setAttribute("data-coalition", unit.getMissionData().coalition); diff --git a/client/src/server/server.ts b/client/src/server/server.ts index f8648eb5..2786852c 100644 --- a/client/src/server/server.ts +++ b/client/src/server/server.ts @@ -29,15 +29,22 @@ export function setCredentials(newUsername: string, newCredentials: string) { credentials = newCredentials; } -export function GET(callback: CallableFunction, uri: string, options?: string) { +export function GET(callback: CallableFunction, uri: string, options?: {time?: number}) { var xmlHttp = new XMLHttpRequest(); - xmlHttp.open("GET", `${demoEnabled? DEMO_ADDRESS: REST_ADDRESS}/${uri}${options? options: ''}`, true); + + /* Assemble the request options string */ + var optionsString = ''; + if (options?.time != undefined) + optionsString = `time=${options.time}`; + + + xmlHttp.open("GET", `${demoEnabled? DEMO_ADDRESS: REST_ADDRESS}/${uri}${optionsString? `?${optionsString}`: ''}`, true); if (credentials) xmlHttp.setRequestHeader("Authorization", "Basic " + credentials); xmlHttp.onload = function (e) { if (xmlHttp.status == 200) { var data = JSON.parse(xmlHttp.responseText); - if (uri !== UNITS_URI || parseInt(data.time) > lastUpdateTime) + if (uri !== UNITS_URI || (options?.time == 0) || parseInt(data.time) > lastUpdateTime) { callback(data); lastUpdateTime = parseInt(data.time); @@ -106,7 +113,7 @@ export function getMission(callback: CallableFunction) { } export function getUnits(callback: CallableFunction, refresh: boolean = false) { - GET(callback, `${UNITS_URI}`, `?time=${refresh? 0: lastUpdateTime}`); + GET(callback, `${UNITS_URI}`, {time: refresh? 0: lastUpdateTime}); } export function addDestination(ID: number, path: any) { diff --git a/client/src/units/unit.ts b/client/src/units/unit.ts index 2170e53b..eb4ef516 100644 --- a/client/src/units/unit.ts +++ b/client/src/units/unit.ts @@ -772,23 +772,25 @@ export class Unit extends CustomMarker { #drawTargets() { for (let index in this.getMissionData().targets) { var targetData = this.getMissionData().targets[index]; - var target = getUnitsManager().getUnitByID(targetData.object["id_"]) - if (target != null) { - var startLatLng = new LatLng(this.getFlightData().latitude, this.getFlightData().longitude) - var endLatLng = new LatLng(target.getFlightData().latitude, target.getFlightData().longitude) + if (targetData.object != undefined){ + var target = getUnitsManager().getUnitByID(targetData.object["id_"]) + if (target != null) { + var startLatLng = new LatLng(this.getFlightData().latitude, this.getFlightData().longitude) + var endLatLng = new LatLng(target.getFlightData().latitude, target.getFlightData().longitude) - var color; - if (targetData.detectionMethod === "RADAR") - color = "#FFFF00"; - else if (targetData.detectionMethod === "VISUAL") - color = "#FF00FF"; - else if (targetData.detectionMethod === "RWR") - color = "#00FF00"; - else - color = "#FFFFFF"; - var targetPolyline = new Polyline([startLatLng, endLatLng], { color: color, weight: 3, opacity: 0.4, smoothFactor: 1 }); - targetPolyline.addTo(getMap()); - this.#targetsPolylines.push(targetPolyline) + var color; + if (targetData.detectionMethod === "RADAR") + color = "#FFFF00"; + else if (targetData.detectionMethod === "VISUAL") + color = "#FF00FF"; + else if (targetData.detectionMethod === "RWR") + color = "#00FF00"; + else + color = "#FFFFFF"; + var targetPolyline = new Polyline([startLatLng, endLatLng], { color: color, weight: 3, opacity: 0.4, smoothFactor: 1 }); + targetPolyline.addTo(getMap()); + this.#targetsPolylines.push(targetPolyline) + } } } } @@ -851,7 +853,7 @@ export class GroundUnit extends Unit { showVvi: false, showHotgroup: true, showUnitIcon: true, - showShortLabel: true, + showShortLabel: false, showFuel: false, showAmmo: false, showSummary: false,