Clean
This commit is contained in:
58
src/App.vue
58
src/App.vue
@@ -149,18 +149,7 @@
|
|||||||
import { useExport } from './composables/useExport';
|
import { useExport } from './composables/useExport';
|
||||||
import type { SpriteFile } from './types/sprites';
|
import type { SpriteFile } from './types/sprites';
|
||||||
|
|
||||||
const {
|
const { sprites, columns, updateSpritePosition, updateSpriteCell, removeSprite, replaceSprite, addSprite, addSpriteWithResize, processImageFiles, alignSprites } = useSprites();
|
||||||
sprites,
|
|
||||||
columns,
|
|
||||||
updateSpritePosition,
|
|
||||||
updateSpriteCell,
|
|
||||||
removeSprite,
|
|
||||||
replaceSprite,
|
|
||||||
addSprite,
|
|
||||||
addSpriteWithResize,
|
|
||||||
processImageFiles,
|
|
||||||
alignSprites,
|
|
||||||
} = useSprites();
|
|
||||||
|
|
||||||
const { downloadSpritesheet, exportSpritesheetJSON, importSpritesheetJSON, downloadAsGif, downloadAsZip } = useExport(sprites, columns);
|
const { downloadSpritesheet, exportSpritesheetJSON, importSpritesheetJSON, downloadAsGif, downloadAsZip } = useExport(sprites, columns);
|
||||||
const isPreviewModalOpen = ref(false);
|
const isPreviewModalOpen = ref(false);
|
||||||
@@ -174,7 +163,6 @@
|
|||||||
const showFeedbackPopup = ref(false);
|
const showFeedbackPopup = ref(false);
|
||||||
|
|
||||||
const handleSpritesUpload = async (files: File[]) => {
|
const handleSpritesUpload = async (files: File[]) => {
|
||||||
// Check if any of the files is a JSON file
|
|
||||||
const jsonFile = files.find(file => file.type === 'application/json' || file.name.endsWith('.json'));
|
const jsonFile = files.find(file => file.type === 'application/json' || file.name.endsWith('.json'));
|
||||||
|
|
||||||
if (jsonFile) {
|
if (jsonFile) {
|
||||||
@@ -187,37 +175,28 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's a single image file that might be a spritesheet
|
|
||||||
if (files.length === 1 && files[0].type.startsWith('image/')) {
|
if (files.length === 1 && files[0].type.startsWith('image/')) {
|
||||||
const file = files[0];
|
const file = files[0];
|
||||||
const url = URL.createObjectURL(file);
|
const url = URL.createObjectURL(file);
|
||||||
|
|
||||||
// Load the image to check its dimensions
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
// Ask the user if they want to split the spritesheet
|
|
||||||
if (confirm('This looks like it might be a spritesheet. Would you like to split it into individual sprites?')) {
|
if (confirm('This looks like it might be a spritesheet. Would you like to split it into individual sprites?')) {
|
||||||
// Open the spritesheet splitter
|
|
||||||
spritesheetImageUrl.value = url;
|
spritesheetImageUrl.value = url;
|
||||||
spritesheetImageFile.value = file;
|
spritesheetImageFile.value = file;
|
||||||
isSpritesheetSplitterOpen.value = true;
|
isSpritesheetSplitterOpen.value = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user doesn't want to split or it's not large enough, process as a single sprite
|
|
||||||
processImageFiles([file]);
|
processImageFiles([file]);
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process multiple image files normally
|
|
||||||
processImageFiles(files);
|
processImageFiles(files);
|
||||||
};
|
};
|
||||||
|
|
||||||
// sprite position and export/import/dl handled by composables
|
|
||||||
|
|
||||||
// Preview modal control
|
|
||||||
const openPreviewModal = () => {
|
const openPreviewModal = () => {
|
||||||
if (sprites.value.length === 0) {
|
if (sprites.value.length === 0) {
|
||||||
alert('Please upload or import sprites to preview an animation.');
|
alert('Please upload or import sprites to preview an animation.');
|
||||||
@@ -230,7 +209,6 @@
|
|||||||
isPreviewModalOpen.value = false;
|
isPreviewModalOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Help modal control
|
|
||||||
const openHelpModal = () => {
|
const openHelpModal = () => {
|
||||||
isHelpModalOpen.value = true;
|
isHelpModalOpen.value = true;
|
||||||
};
|
};
|
||||||
@@ -239,7 +217,6 @@
|
|||||||
isHelpModalOpen.value = false;
|
isHelpModalOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Feedback modal control
|
|
||||||
const openFeedbackModal = () => {
|
const openFeedbackModal = () => {
|
||||||
isFeedbackModalOpen.value = true;
|
isFeedbackModalOpen.value = true;
|
||||||
};
|
};
|
||||||
@@ -248,10 +225,8 @@
|
|||||||
isFeedbackModalOpen.value = false;
|
isFeedbackModalOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Spritesheet splitter modal control
|
|
||||||
const closeSpritesheetSplitter = () => {
|
const closeSpritesheetSplitter = () => {
|
||||||
isSpritesheetSplitterOpen.value = false;
|
isSpritesheetSplitterOpen.value = false;
|
||||||
// Clean up the URL object to prevent memory leaks
|
|
||||||
if (spritesheetImageUrl.value) {
|
if (spritesheetImageUrl.value) {
|
||||||
URL.revokeObjectURL(spritesheetImageUrl.value);
|
URL.revokeObjectURL(spritesheetImageUrl.value);
|
||||||
spritesheetImageUrl.value = '';
|
spritesheetImageUrl.value = '';
|
||||||
@@ -259,7 +234,6 @@
|
|||||||
spritesheetImageFile.value = null;
|
spritesheetImageFile.value = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// GIF FPS modal control
|
|
||||||
const openGifFpsModal = () => {
|
const openGifFpsModal = () => {
|
||||||
if (sprites.value.length === 0) {
|
if (sprites.value.length === 0) {
|
||||||
alert('Please upload or import sprites before generating a GIF.');
|
alert('Please upload or import sprites before generating a GIF.');
|
||||||
@@ -272,20 +246,14 @@
|
|||||||
isGifFpsModalOpen.value = false;
|
isGifFpsModalOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle the split spritesheet result
|
|
||||||
const handleSplitSpritesheet = (spriteFiles: SpriteFile[]) => {
|
const handleSplitSpritesheet = (spriteFiles: SpriteFile[]) => {
|
||||||
// For now ignore bounding box offsets; add all files as new sprites
|
|
||||||
processImageFiles(spriteFiles.map(s => s.file));
|
processImageFiles(spriteFiles.map(s => s.file));
|
||||||
};
|
};
|
||||||
|
|
||||||
// export handled by composable
|
|
||||||
|
|
||||||
// Open file dialog for JSON import
|
|
||||||
const openJSONImportDialog = () => {
|
const openJSONImportDialog = () => {
|
||||||
jsonFileInput.value?.click();
|
jsonFileInput.value?.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle JSON file selection
|
|
||||||
const handleJSONFileChange = async (event: Event) => {
|
const handleJSONFileChange = async (event: Event) => {
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
if (input.files && input.files.length > 0) {
|
if (input.files && input.files.length > 0) {
|
||||||
@@ -296,39 +264,19 @@
|
|||||||
console.error('Error importing JSON:', error);
|
console.error('Error importing JSON:', error);
|
||||||
alert('Failed to import JSON file. Please check the file format.');
|
alert('Failed to import JSON file. Please check the file format.');
|
||||||
}
|
}
|
||||||
// Reset input value so uploading the same file again will trigger the event
|
|
||||||
if (jsonFileInput.value) jsonFileInput.value.value = '';
|
if (jsonFileInput.value) jsonFileInput.value.value = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// import handled by composable (used in handleSpritesUpload/handleJSONFileChange)
|
|
||||||
|
|
||||||
// alignment handled by composable (exposed as alignSprites)
|
|
||||||
|
|
||||||
// cell update handled by composable (exposed as updateSpriteCell)
|
|
||||||
|
|
||||||
// remove handled by composable
|
|
||||||
|
|
||||||
// replace handled by composable
|
|
||||||
|
|
||||||
// add handled by composable
|
|
||||||
|
|
||||||
// add with resize handled by composable
|
|
||||||
|
|
||||||
// GIF handled by composable
|
|
||||||
|
|
||||||
// Check for one-time feedback popup on mount
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const hasShownFeedbackPopup = localStorage.getItem('hasShownFeedbackPopup');
|
const hasShownFeedbackPopup = localStorage.getItem('hasShownFeedbackPopup');
|
||||||
if (!hasShownFeedbackPopup) {
|
if (!hasShownFeedbackPopup) {
|
||||||
// Show popup after a short delay to let the page load
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
showFeedbackPopup.value = true;
|
showFeedbackPopup.value = true;
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle feedback popup response
|
|
||||||
const handleFeedbackPopupResponse = (showModal: boolean) => {
|
const handleFeedbackPopupResponse = (showModal: boolean) => {
|
||||||
showFeedbackPopup.value = false;
|
showFeedbackPopup.value = false;
|
||||||
localStorage.setItem('hasShownFeedbackPopup', 'true');
|
localStorage.setItem('hasShownFeedbackPopup', 'true');
|
||||||
@@ -337,8 +285,4 @@
|
|||||||
openFeedbackModal();
|
openFeedbackModal();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// unmount cleanup is handled inside useSprites
|
|
||||||
|
|
||||||
// ZIP handled by composable
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
<!-- Resize handle -->
|
<!-- Resize handle -->
|
||||||
<div v-if="!isFullScreen && !isMobile" class="absolute bottom-0 right-0 w-8 h-8 cursor-se-resize" @mousedown="startResize" @touchstart="startResize">
|
<div v-if="!isFullScreen && !isMobile" class="absolute bottom-0 right-0 w-8 h-8 cursor-se-resize" @mousedown="startResize" @touchstart="startResize">
|
||||||
<svg class="w-8 h-8 text-gray-400 dark:text-gray-500" viewBox="0 0 24 24" fill="currentColor">
|
<svg class="w-8 h-8 text-gray-400 dark:text-gray-500" viewBox="0 0 24 24" fill="currentColor">
|
||||||
<path d="M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22Z"/>
|
<path d="M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22Z" />
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user