mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fix layer handling in cutter (#352)
* Fix layer handling in cutter * Remove unused variable in `cloneFilteredByquadrants()` * Rework check in `isValidShortKeyInternal()` to being an early return * Support empty layers in `isValidShortKeyInternal()` which aren't the topmost layer
This commit is contained in:
parent
ef574c0bfe
commit
97870da048
@ -183,6 +183,11 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
*/
|
*/
|
||||||
static isValidShortKeyInternal(key) {
|
static isValidShortKeyInternal(key) {
|
||||||
const sourceLayers = key.split(":");
|
const sourceLayers = key.split(":");
|
||||||
|
|
||||||
|
if (sourceLayers.length === 0 || sourceLayers.length > 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let layers = [];
|
let layers = [];
|
||||||
for (let i = 0; i < sourceLayers.length; ++i) {
|
for (let i = 0; i < sourceLayers.length; ++i) {
|
||||||
const text = sourceLayers[i];
|
const text = sourceLayers[i];
|
||||||
@ -221,15 +226,12 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!anyFilled) {
|
if (!anyFilled && i === sourceLayers.length - 1) {
|
||||||
// Empty layer
|
// Topmost layer isn't allowed being empty
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
layers.push(quads);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layers.length === 0 || layers.length > 4) {
|
layers.push(quads);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -447,23 +449,23 @@ export class ShapeDefinition extends BasicSerializableObject {
|
|||||||
*/
|
*/
|
||||||
cloneFilteredByQuadrants(includeQuadrants) {
|
cloneFilteredByQuadrants(includeQuadrants) {
|
||||||
const newLayers = this.internalCloneLayers();
|
const newLayers = this.internalCloneLayers();
|
||||||
|
let lastNonEmptyLayer = -1;
|
||||||
for (let layerIndex = 0; layerIndex < newLayers.length; ++layerIndex) {
|
for (let layerIndex = 0; layerIndex < newLayers.length; ++layerIndex) {
|
||||||
const quadrants = newLayers[layerIndex];
|
const quadrants = newLayers[layerIndex];
|
||||||
let anyContents = false;
|
|
||||||
for (let quadrantIndex = 0; quadrantIndex < 4; ++quadrantIndex) {
|
for (let quadrantIndex = 0; quadrantIndex < 4; ++quadrantIndex) {
|
||||||
if (includeQuadrants.indexOf(quadrantIndex) < 0) {
|
if (includeQuadrants.indexOf(quadrantIndex) < 0) {
|
||||||
quadrants[quadrantIndex] = null;
|
quadrants[quadrantIndex] = null;
|
||||||
} else if (quadrants[quadrantIndex]) {
|
} 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 });
|
return new ShapeDefinition({ layers: newLayers });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user