[FEAT] Calc. fixes

This commit is contained in:
2026-01-01 01:39:03 +01:00
parent e916c80d00
commit ab939c202e
2 changed files with 9 additions and 7 deletions

View File

@@ -20,10 +20,11 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
};
}
// Otherwise, calculate from sprite dimensions
const visibleLayers = getVisibleLayers();
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers);
const negativeSpacing = calculateNegativeSpacing(getAllVisibleSprites(), negativeSpacingEnabled.value);
// Otherwise, calculate from sprite dimensions across ALL layers (same as canvas)
// This ensures export dimensions match what's shown in the canvas
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(layersRef.value);
const allSprites = getVisibleLayers().flatMap(l => l.sprites);
const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value);
return {
cellWidth: maxWidth + negativeSpacing,
cellHeight: maxHeight + negativeSpacing,

View File

@@ -356,8 +356,9 @@ export const useLayers = () => {
};
};
export const getMaxDimensionsAcrossLayers = (layers: Layer[]) => {
// Consider ALL layers regardless of visibility to keep canvas size stable
const sprites = layers.flatMap(l => l.sprites);
export const getMaxDimensionsAcrossLayers = (layers: Layer[], visibleOnly: boolean = false) => {
// When visibleOnly is false (default), consider ALL layers to keep canvas size stable
// When visibleOnly is true (export), only consider visible layers
const sprites = layers.flatMap(l => (visibleOnly ? (l.visible ? l.sprites : []) : l.sprites));
return getMaxDimensionsSingle(sprites);
};