From bcc2faca350f9702c5f7ed76f79c264108fe01ca Mon Sep 17 00:00:00 2001 From: root Date: Wed, 7 Jan 2026 16:20:08 +0100 Subject: [PATCH] [FEAT] Open project bug fix --- src/composables/useExportLayers.ts | 20 ++++++++++++++++++++ src/composables/useProjectManager.ts | 26 +++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/composables/useExportLayers.ts b/src/composables/useExportLayers.ts index 71b9706..ebb46e7 100644 --- a/src/composables/useExportLayers.ts +++ b/src/composables/useExportLayers.ts @@ -164,6 +164,26 @@ export const useExportLayers = (layersRef: Ref, columns: Ref, n const file = new File([blob], fileName, { type: mimeType }); resolve({ id: spriteData.id || crypto.randomUUID(), file, img, url: spriteData.base64, width: spriteData.width, height: spriteData.height, x: spriteData.x || 0, y: spriteData.y || 0, rotation: spriteData.rotation || 0, flipX: spriteData.flipX || false, flipY: spriteData.flipY || false }); }; + img.onerror = () => { + console.error('Failed to load sprite image:', spriteData.name); + // Create a 1x1 transparent placeholder or similar to avoid breaking the entire project load + // For now, we'll just resolve with a "broken" sprite but maybe with 0 width/height effectively + // or we could construct a dummy file. + // Let's resolve with a valid but empty/placeholder structure to let other sprites load. + resolve({ + id: spriteData.id || crypto.randomUUID(), + file: new File([], 'broken-image'), + img: new Image(), // Empty image + url: '', + width: 0, + height: 0, + x: spriteData.x || 0, + y: spriteData.y || 0, + rotation: 0, + flipX: false, + flipY: false, + }); + }; img.src = spriteData.base64; }); diff --git a/src/composables/useProjectManager.ts b/src/composables/useProjectManager.ts index 9be8b0a..e77bf86 100644 --- a/src/composables/useProjectManager.ts +++ b/src/composables/useProjectManager.ts @@ -39,10 +39,30 @@ export const useProjectManager = () => { const openProject = async (project: Project) => { try { - if (project.data) { - await loadProjectData(project.data); + let projectData = project.data; + + // If data is missing, we MUST fetch the full project + if (!projectData) { + await projectStore.loadProject(project.id); + // After loading, the store's currentProject will be updated. + // We should use that data. + if (projectStore.currentProject && projectStore.currentProject.id === project.id) { + projectData = projectStore.currentProject.data; + } } - projectStore.currentProject = project; + + if (projectData) { + await loadProjectData(projectData); + } else { + console.warn('Project opened but no data found (even after fetch attempt). Opening empty.'); + } + + // Ensure we set the current project in the store if we passed in a project that might have been partial, + // but rely on what's in the store if we just fetched it. + if (!projectStore.currentProject || projectStore.currentProject.id !== project.id) { + projectStore.currentProject = project; + } + router.push({ name: 'editor', params: { id: project.id } }); } catch (e) { console.error('Failed to open project', e);