Added command hash control

This commit is contained in:
Pax1601 2023-09-05 17:25:32 +02:00
parent cbb878cf96
commit a96a6eb57d
3 changed files with 28 additions and 15 deletions

View File

@ -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() {

View File

@ -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() {

View File

@ -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());
}
}
}