1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Fix layer handling in cutter

This commit is contained in:
cyantree - Christoph Schreiber 2020-06-30 15:34:05 +02:00
parent 8667739e5e
commit 54594b37b7

View File

@ -441,6 +441,7 @@ export class ShapeDefinition extends BasicSerializableObject {
*/
cloneFilteredByQuadrants(includeQuadrants) {
const newLayers = this.internalCloneLayers();
let lastNonEmptyLayer = -1;
for (let layerIndex = 0; layerIndex < newLayers.length; ++layerIndex) {
const quadrants = newLayers[layerIndex];
let anyContents = false;
@ -448,16 +449,16 @@ export class ShapeDefinition extends BasicSerializableObject {
if (includeQuadrants.indexOf(quadrantIndex) < 0) {
quadrants[quadrantIndex] = null;
} else if (quadrants[quadrantIndex]) {
anyContents = true;
lastNonEmptyLayer = layerIndex;
}
}
// Check if the layer is entirely empty
if (!anyContents) {
newLayers.splice(layerIndex, 1);
layerIndex -= 1;
}
}
// Remove top most empty layers which aren't needed anymore
if (lastNonEmptyLayer !== newLayers.length - 1) {
newLayers.splice(lastNonEmptyLayer + 1);
}
return new ShapeDefinition({ layers: newLayers });
}