diff --git a/src/components/SpritePreview.vue b/src/components/SpritePreview.vue index 97c24ec..6686265 100644 --- a/src/components/SpritePreview.vue +++ b/src/components/SpritePreview.vue @@ -13,6 +13,10 @@ Flip Vertical + + + Replace Sprite + Copy to Frame... @@ -292,6 +296,8 @@ + + @@ -317,6 +323,7 @@ (e: 'rotateSprite', id: string, angle: number): void; (e: 'flipSprite', id: string, direction: 'horizontal' | 'vertical'): void; (e: 'copySpriteToFrame', spriteId: string, targetLayerId: string, targetFrameIndex: number): void; + (e: 'replaceSprite', id: string, file: File): void; }>(); const previewContainerRef = ref(null); @@ -362,6 +369,8 @@ const contextMenuY = ref(0); const contextMenuSpriteId = ref(null); const contextMenuLayerId = ref(null); + const fileInput = ref(null); + const replacingSpriteId = ref(null); // Copy to frame modal state const showCopyToFrameModal = ref(false); @@ -720,6 +729,27 @@ contextMenuSpriteId.value = null; } }; + + const replaceSprite = () => { + if (contextMenuSpriteId.value && fileInput.value) { + replacingSpriteId.value = contextMenuSpriteId.value; + fileInput.value.click(); + hideContextMenu(); + } + }; + + const handleFileChange = (event: Event) => { + const input = event.target as HTMLInputElement; + + if (input.files && input.files.length > 0) { + const file = input.files[0]; + if (file.type.startsWith('image/') && replacingSpriteId.value) { + emit('replaceSprite', replacingSpriteId.value, file); + } + } + replacingSpriteId.value = null; + input.value = ''; + };