From 187664e36ae5b4a4ca0f553f49b937740dce98d2 Mon Sep 17 00:00:00 2001 From: MatCat Date: Sat, 13 Mar 2021 18:51:31 -0800 Subject: [PATCH] WIP: Copy/paste locationing --- js/globalfunctions.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/js/globalfunctions.js b/js/globalfunctions.js index 14e7b84..0f72efa 100644 --- a/js/globalfunctions.js +++ b/js/globalfunctions.js @@ -365,6 +365,11 @@ function loadActiveContainer(Elements) { let elementConnections = new Array(); let icelementConnections = new Array(); let designatorMap = new Array(); + let selectedObjects = new Array(); + let lowestX = 9999999999; + let lowestY = 9999999999; + let highestX = 0; + let highestY = 0; for (let a = 0; a < Elements.length; a++) { if (Elements[a].IsIC) { @@ -379,10 +384,17 @@ function loadActiveContainer(Elements) { let classRef = getElementInfo(Elements[a].Name).Class; let newElement = new classRef(logicEngine.ActiveContainer,Elements[a],logicEngine,getElementInfo(Elements[a].Name).Args[0]); + if (newElement) selectedObjects.push(newElement); logicEngine.ActiveContainer.AddElement(newElement); newElement.X -= logicEngine.Panning.OffsetX; newElement.Y -= logicEngine.Panning.OffsetY; + + if (newElement.X < lowestX) lowestX = newElement.X; + if (newElement.X > highestX) highestX = newElement.X; + if (newElement.Y < lowestY) lowestY = newElement.Y; + if (newElement.Y > highestY) highestY = newElement.Y; + designatorMap.push({Old: Elements[a].Designator, New: newElement.Designator}); if (Elements[a].Outputs) { @@ -412,6 +424,23 @@ function loadActiveContainer(Elements) { } } + logicEngine.ActiveContainer.Selected = selectedObjects; + logicEngine.MovingElement = new Array(logicEngine.ActiveContainer.Selected.length); + + for (let b = 0; b < logicEngine.ActiveContainer.Selected.length; b++) { + //logicEngine.ActiveContainer.Selected[b].X = (logicEngine.ActiveContainer.Selected[b].X - ((highestX-lowestX)/2)) + logicEngine.Mouse.x; + logicEngine.ActiveContainer.Selected[b].X = (logicEngine.ActiveContainer.Selected[b].X - lowestX) + logicEngine.Mouse.x - ((highestX-lowestX)/2); + //logicEngine.ActiveContainer.Selected[b].Y = (logicEngine.ActiveContainer.Selected[b].Y - ((highestY-lowestY)/2)) + logicEngine.Mouse.y; + logicEngine.ActiveContainer.Selected[b].Y = (logicEngine.ActiveContainer.Selected[b].Y - lowestY) + logicEngine.Mouse.y - ((highestY-lowestY)/2); + logicEngine.MovingElement[b] = { + StartX: logicEngine.ActiveContainer.Selected[b].X, + StartY: logicEngine.ActiveContainer.Selected[b].Y + }; + logicEngine.MovingElementMouseStartX = logicEngine.Mouse.x; + logicEngine.MovingElementMouseStartY = logicEngine.Mouse.y; + } + logicEngine.MouseDown = true; + for (let a = 0; a < elementConnections.length; a++) { let toElement = logicEngine.ActiveContainer.HasElement(getPastedElementDesignator(designatorMap,elementConnections[a].ToElement)); if (toElement) {