Commit 5245720b authored by Christian Winter's avatar Christian Winter

instance selection bugfixes and box selection

parent 2bd016da
Pipeline #4766546 passed with stage
in 54 seconds
......@@ -53,6 +53,22 @@ class PrefabInstance {
return false;
}
selectionBoxHit(bounds) {
for (let line of this.reference.lines) {
line = line.copy().move(this.transform.position);
line.start.position = line.start.position.scaleFrom(this.transform.position, this.transform.scale);
line.start.position = line.start.position.rotateAround(this.transform.position, this.transform.rotation);
line.end.position = line.end.position.scaleFrom(this.transform.position, this.transform.scale);
line.end.position = line.end.position.rotateAround(this.transform.position, this.transform.rotation);
if (bounds.contains(line.start) || bounds.contains(line.end))
return true;
}
return false;
}
get bounds() {
let min = new Vector2(Infinity, Infinity);
let max = new Vector2(-Infinity, -Infinity);
......
......@@ -69,8 +69,7 @@
}
removePrefabInstance(instance) {
Utilities.deleteArrayEntry(
getInstancesForPrefab(instance.reference), instance);
Utilities.deleteArrayEntry(getInstancesForPrefab(instance.reference), instance);
}
cleanUp() {
......
......@@ -155,6 +155,11 @@ class MouseHandler {
let instances = kv[1];
for (let instance of instances)
if (instance.selectionHit())
prefabInstancesToChangeSelection.push(instance);
}
for (let instance of Selection.data.prefabInstances)
{
if (instance.selectionHit())
prefabInstancesToChangeSelection.push(instance);
}
// */
......@@ -176,7 +181,16 @@ class MouseHandler {
Selection.changeSelectionForPoints(pointsToChangeSelection);
for (let instance of prefabInstancesToChangeSelection)
Selection.data.addPrefabInstance(instance);
{
if (Selection.data.prefabInstances.includes(instance))
{
File.currentLayer.prefabDict.addInstance(instance);
Selection.data.removePrefabInstance(instance);
} else {
Selection.data.addPrefabInstance(instance);
File.currentLayer.prefabDict.removeInstance(instance);
}
}
if (pointsToChangeSelection.length > 0 || prefabInstancesToChangeSelection.length > 0) {
......
......@@ -27,8 +27,10 @@
for (let kv of File.currentLayer.prefabDict.keyValuePairs) {
let prefab = kv[0];
let instances = kv[1];
for (let i = instances.length - 1; i >= 0; --i)
for (let i = instances.length - 1; i >= 0; --i) {
Selection.data.addPrefabInstance(instances[i]);
File.currentLayer.prefabDict.removeInstance(instances[i]);
}
}
this.data.changed();
......@@ -53,8 +55,10 @@
for (let kv of File.currentLayer.prefabDict.keyValuePairs) {
let prefab = kv[0];
let instances = kv[1];
for (let i = instances.length - 1; i >= 0; --i)
for (let i = instances.length - 1; i >= 0; --i) {
Selection.data.addPrefabInstance(instances[i]);
File.currentLayer.prefabDict.removeInstance(instances[i]);
}
}
for (let instance of tmp)
File.currentLayer.prefabDict.addInstance(instance);
......@@ -245,11 +249,17 @@ class SelectionData {
addPrefabInstance(instance) {
if (this.prefabInstances.includes(instance))
return;
File.currentLayer.prefabDict.removeInstance(instance);
this.prefabInstances.push(instance);
}
removePrefabInstance(instance) {
if (!this.prefabInstances.includes(instance))
return;
// File.currentLayer.prefabDict.addInstance(instance);
Utilities.deleteArrayEntry(this.prefabInstances, instance);
}
copy() {
let newSelData = new SelectionData();
......
......@@ -84,12 +84,42 @@
for (let p of points)
if (selectionBounds.contains(p))
changePoints.push(p);
}
}
if (selectionType)
Selection.selectPoints(changePoints);
else
Selection.selectPoints(changePoints);
else
Selection.deselectPoints(changePoints);
// prefab instances
let prefabInstancesToChangeSelection = [];
if (selectionType) {
for (let kv of File.currentLayer.prefabDict.keyValuePairs) {
let prefab = kv[0];
let instances = kv[1];
for (let instance of instances)
if (instance.selectionBoxHit(selectionBounds))
prefabInstancesToChangeSelection.push(instance);
}
for (let instance of prefabInstancesToChangeSelection)
{
Selection.data.addPrefabInstance(instance);
File.currentLayer.prefabDict.removeInstance(instance);
}
}
else {
for (let instance of Selection.data.prefabInstances)
if (instance.selectionBoxHit(selectionBounds))
prefabInstancesToChangeSelection.push(instance);
for (let instance of prefabInstancesToChangeSelection)
{
File.currentLayer.prefabDict.addInstance(instance);
Selection.data.removePrefabInstance(instance);
}
}
}
cancel() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment