Added ability to delete original cloned units

Mostly useful to group units together
This commit is contained in:
Pax1601
2023-09-07 13:02:14 +02:00
parent e2f80c5788
commit 09bf361d44
6 changed files with 128 additions and 77 deletions

View File

@@ -199,8 +199,8 @@ export function followUnit(ID: number, targetID: number, offset: { "x": number,
POST(data, callback);
}
export function cloneUnits(units: {ID: number, location: LatLng}[], callback: CallableFunction = () => {}) {
var command = { "units": units };
export function cloneUnits(units: {ID: number, location: LatLng}[], deleteOriginal: boolean, callback: CallableFunction = () => {}) {
var command = { "units": units, "deleteOriginal": deleteOriginal };
var data = { "cloneUnits": command }
POST(data, callback);
}

View File

@@ -555,7 +555,6 @@ export class UnitsManager {
this.#showActionMessage(selectedUnits, `unit bombing point`);
}
// TODO handle from lua
selectedUnitsCreateGroup() {
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false });
var units: { ID: number, location: LatLng }[] = [];
@@ -563,13 +562,11 @@ export class UnitsManager {
var unit = selectedUnits[idx];
units.push({ ID: unit.ID, location: unit.getPosition() });
}
cloneUnits(units, () => {
cloneUnits(units, true, () => {
units.forEach((unit: any) => {
deleteUnit(unit.ID, false, false);
});
});
});
}
/***********************************************/
@@ -608,7 +605,7 @@ export class UnitsManager {
units.push({ ID: unit.ID, location: position });
});
cloneUnits(units, (res: any) => {
cloneUnits(units, false, (res: any) => {
if (res.commandHash !== undefined) {
markers.forEach((marker: TemporaryUnitMarker) => {
marker.setCommandHash(res.commandHash);