[FEAT] PNG export fix
This commit is contained in:
@@ -2,11 +2,12 @@ import type { Ref } from 'vue';
|
|||||||
import GIF from 'gif.js';
|
import GIF from 'gif.js';
|
||||||
import gifWorkerUrl from 'gif.js/dist/gif.worker.js?url';
|
import gifWorkerUrl from 'gif.js/dist/gif.worker.js?url';
|
||||||
import JSZip from 'jszip';
|
import JSZip from 'jszip';
|
||||||
import type { Sprite } from '../types/sprites';
|
import type { Layer, Sprite } from '../types/sprites';
|
||||||
import { getMaxDimensions } from './useSprites';
|
import { getMaxDimensions } from './useSprites';
|
||||||
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
import { calculateNegativeSpacing } from './useNegativeSpacing';
|
||||||
|
import { getMaxDimensionsAcrossLayers } from './useLayers';
|
||||||
|
|
||||||
export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, backgroundColor?: Ref<string>, manualCellSizeEnabled?: Ref<boolean>, manualCellWidth?: Ref<number>, manualCellHeight?: Ref<number>) => {
|
export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negativeSpacingEnabled: Ref<boolean>, backgroundColor?: Ref<string>, manualCellSizeEnabled?: Ref<boolean>, manualCellWidth?: Ref<number>, manualCellHeight?: Ref<number>, layers?: Ref<Layer[]>) => {
|
||||||
const getCellDimensions = () => {
|
const getCellDimensions = () => {
|
||||||
// If manual cell size is enabled, use manual values
|
// If manual cell size is enabled, use manual values
|
||||||
if (manualCellSizeEnabled?.value) {
|
if (manualCellSizeEnabled?.value) {
|
||||||
@@ -17,9 +18,14 @@ export const useExport = (sprites: Ref<Sprite[]>, columns: Ref<number>, negative
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, calculate from sprite dimensions
|
// Use dimensions from ALL layers to keep canvas size stable when hiding layers
|
||||||
const { maxWidth, maxHeight } = getMaxDimensions(sprites.value);
|
// Fall back to current sprites if layers ref is not provided
|
||||||
const negativeSpacing = calculateNegativeSpacing(sprites.value, negativeSpacingEnabled.value);
|
const { maxWidth, maxHeight } = layers?.value ? getMaxDimensionsAcrossLayers(layers.value, false) : getMaxDimensions(sprites.value);
|
||||||
|
|
||||||
|
// Calculate negative spacing from all layers' sprites for consistency
|
||||||
|
const allSprites = layers?.value ? layers.value.flatMap(l => l.sprites) : sprites.value;
|
||||||
|
const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cellWidth: maxWidth + negativeSpacing,
|
cellWidth: maxWidth + negativeSpacing,
|
||||||
cellHeight: maxHeight + negativeSpacing,
|
cellHeight: maxHeight + negativeSpacing,
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, n
|
|||||||
// Otherwise, calculate from sprite dimensions across ALL layers (same as canvas)
|
// Otherwise, calculate from sprite dimensions across ALL layers (same as canvas)
|
||||||
// This ensures export dimensions match what's shown in the canvas
|
// This ensures export dimensions match what's shown in the canvas
|
||||||
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(layersRef.value);
|
const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(layersRef.value);
|
||||||
const allSprites = getVisibleLayers().flatMap(l => l.sprites);
|
// Calculate negative spacing from ALL layers (not just visible) to keep canvas size stable
|
||||||
|
const allSprites = layersRef.value.flatMap(l => l.sprites);
|
||||||
const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value);
|
const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value);
|
||||||
return {
|
return {
|
||||||
cellWidth: maxWidth + negativeSpacing,
|
cellWidth: maxWidth + negativeSpacing,
|
||||||
|
|||||||
Reference in New Issue
Block a user