From a96a6eb57d49c7c048c5f4a52a2445178a528f9f Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Tue, 5 Sep 2023 17:25:32 +0200 Subject: [PATCH] Added command hash control --- client/src/map/map.ts | 1 + client/src/map/temporaryunitmarker.ts | 28 +++++++++++++++------------ client/src/unit/unitsmanager.ts | 14 +++++++++++--- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/client/src/map/map.ts b/client/src/map/map.ts index 70b8adcd..0806115d 100644 --- a/client/src/map/map.ts +++ b/client/src/map/map.ts @@ -429,6 +429,7 @@ export class Map extends L.Map { var marker = new TemporaryUnitMarker(latlng, name, coalition, commandHash); marker.addTo(this); this.#temporaryMarkers.push(marker); + return marker; } getSelectedCoalitionArea() { diff --git a/client/src/map/temporaryunitmarker.ts b/client/src/map/temporaryunitmarker.ts index ffda032a..97f93d4f 100644 --- a/client/src/map/temporaryunitmarker.ts +++ b/client/src/map/temporaryunitmarker.ts @@ -17,18 +17,22 @@ export class TemporaryUnitMarker extends CustomMarker { this.#coalition = coalition; this.#commandHash = commandHash; - if (this.#commandHash !== undefined) { - this.#timer = window.setInterval(() => { - if (this.#commandHash !== undefined) { - isCommandExecuted((res: any) => { - if (res.commandExecuted) { - this.removeFrom(getMap()); - window.clearInterval(this.#timer); - } - }, this.#commandHash) - } - }, 1000); - } + if (commandHash !== undefined) + this.setCommandHash(commandHash) + } + + setCommandHash(commandHash: string) { + this.#commandHash = commandHash; + this.#timer = window.setInterval(() => { + if (this.#commandHash !== undefined) { + isCommandExecuted((res: any) => { + if (res.commandExecuted) { + this.removeFrom(getMap()); + window.clearInterval(this.#timer); + } + }, this.#commandHash) + } + }, 1000); } createIcon() { diff --git a/client/src/unit/unitsmanager.ts b/client/src/unit/unitsmanager.ts index c44711a4..6785f830 100644 --- a/client/src/unit/unitsmanager.ts +++ b/client/src/unit/unitsmanager.ts @@ -12,6 +12,7 @@ import { citiesDatabase } from "./citiesDatabase"; import { aircraftDatabase } from "./aircraftdatabase"; import { helicopterDatabase } from "./helicopterdatabase"; import { navyUnitDatabase } from "./navyunitdatabase"; +import { TemporaryUnitMarker } from "../map/temporaryunitmarker"; export class UnitsManager { #units: { [ID: number]: Unit }; @@ -603,12 +604,20 @@ export class UnitsManager { /* Clone the units in groups */ for (let groupName in groups) { var units: { ID: number, location: LatLng }[] = []; + var markers: TemporaryUnitMarker[] = []; groups[groupName].forEach((unit: any) => { var position = new LatLng(getMap().getMouseCoordinates().lat + unit.position.lat - avgLat, getMap().getMouseCoordinates().lng + unit.position.lng - avgLng); - getMap().addTemporaryMarker(position, unit.name, unit.coalition); + markers.push(getMap().addTemporaryMarker(position, unit.name, unit.coalition)); units.push({ ID: unit.ID, location: position }); }); - cloneUnits(units); + + cloneUnits(units, (res: any) => { + if (res.commandHash !== undefined) { + markers.forEach((marker: TemporaryUnitMarker) => { + marker.setCommandHash(res.commandHash); + }) + } + }); } getInfoPopup().setText(`${this.#copiedUnits.length} units pasted`); } @@ -635,7 +644,6 @@ export class UnitsManager { const unitBlueprint = randomUnitBlueprint(groundUnitDatabase, { type: type, eras: activeEras, ranges: activeRanges }); if (unitBlueprint) { this.spawnUnits("GroundUnit", [{ unitType: unitBlueprint.name, location: latlng, liveryID: "" }], coalitionArea.getCoalition(), true); - getMap().addTemporaryMarker(latlng, unitBlueprint.name, coalitionArea.getCoalition()); } } }