mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Fixed table deepcopy
This commit is contained in:
@@ -559,10 +559,8 @@ export class UnitsManager {
|
|||||||
selectedUnitsCreateGroup() {
|
selectedUnitsCreateGroup() {
|
||||||
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false });
|
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false });
|
||||||
var units: { ID: number, location: LatLng }[] = [];
|
var units: { ID: number, location: LatLng }[] = [];
|
||||||
var coalition = "neutral";
|
|
||||||
for (let idx in selectedUnits) {
|
for (let idx in selectedUnits) {
|
||||||
var unit = selectedUnits[idx];
|
var unit = selectedUnits[idx];
|
||||||
coalition = unit.getCoalition();
|
|
||||||
units.push({ ID: unit.ID, location: unit.getPosition() });
|
units.push({ ID: unit.ID, location: unit.getPosition() });
|
||||||
}
|
}
|
||||||
cloneUnits(units, () => {
|
cloneUnits(units, () => {
|
||||||
@@ -580,7 +578,6 @@ export class UnitsManager {
|
|||||||
getInfoPopup().setText(`${this.#copiedUnits.length} units copied`);
|
getInfoPopup().setText(`${this.#copiedUnits.length} units copied`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO handle from lua
|
|
||||||
pasteUnits() {
|
pasteUnits() {
|
||||||
if (this.#copiedUnits.length > 0 && !this.#pasteDisabled && getMissionHandler().getCommandModeOptions().commandMode == GAME_MASTER) {
|
if (this.#copiedUnits.length > 0 && !this.#pasteDisabled && getMissionHandler().getCommandModeOptions().commandMode == GAME_MASTER) {
|
||||||
/* Compute the position of the center of the copied units */
|
/* Compute the position of the center of the copied units */
|
||||||
@@ -604,7 +601,7 @@ export class UnitsManager {
|
|||||||
/* Clone the units in groups */
|
/* Clone the units in groups */
|
||||||
for (let groupName in groups) {
|
for (let groupName in groups) {
|
||||||
var units: { ID: number, location: LatLng }[] = [];
|
var units: { ID: number, location: LatLng }[] = [];
|
||||||
var markers: TemporaryUnitMarker[] = [];
|
let markers: TemporaryUnitMarker[] = [];
|
||||||
groups[groupName].forEach((unit: any) => {
|
groups[groupName].forEach((unit: any) => {
|
||||||
var position = new LatLng(getMap().getMouseCoordinates().lat + unit.position.lat - avgLat, getMap().getMouseCoordinates().lng + unit.position.lng - avgLng);
|
var position = new LatLng(getMap().getMouseCoordinates().lat + unit.position.lat - avgLat, getMap().getMouseCoordinates().lng + unit.position.lng - avgLng);
|
||||||
markers.push(getMap().addTemporaryMarker(position, unit.name, unit.coalition));
|
markers.push(getMap().addTemporaryMarker(position, unit.name, unit.coalition));
|
||||||
|
|||||||
@@ -616,7 +616,7 @@ function Olympus.clone(cloneTable)
|
|||||||
local heading = math.atan2( position.x.z, position.x.x )
|
local heading = math.atan2( position.x.z, position.x.x )
|
||||||
|
|
||||||
-- Update the data of the cloned unit
|
-- Update the data of the cloned unit
|
||||||
local unitTable = Olympus.spawnDatabase[unit:getName()]
|
local unitTable = mist.utils.deepCopy(Olympus.spawnDatabase[unit:getName()])
|
||||||
|
|
||||||
local point = coord.LLtoLO(cloneData['lat'], cloneData['lng'], 0)
|
local point = coord.LLtoLO(cloneData['lat'], cloneData['lng'], 0)
|
||||||
if unitTable then
|
if unitTable then
|
||||||
@@ -674,7 +674,7 @@ function Olympus.clone(cloneTable)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unitsTable[#unitsTable + 1] = unitTable
|
unitsTable[#unitsTable + 1] = mist.utils.deepCopy(unitTable)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -688,6 +688,13 @@ function Olympus.clone(cloneTable)
|
|||||||
task = 'CAP'
|
task = 'CAP'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Olympus.debug(Olympus.serializeTable(vars), 1)
|
||||||
|
|
||||||
|
-- Save the units in the database, for cloning
|
||||||
|
for idx, unitTable in pairs(unitsTable) do
|
||||||
|
Olympus.addToDatabase(unitTable)
|
||||||
|
end
|
||||||
|
|
||||||
mist.dynAdd(vars)
|
mist.dynAdd(vars)
|
||||||
Olympus.unitCounter = Olympus.unitCounter + 1
|
Olympus.unitCounter = Olympus.unitCounter + 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user