[FEAT] Open project bug fix

This commit is contained in:
2026-01-07 16:20:08 +01:00
parent f9635ba044
commit bcc2faca35
2 changed files with 43 additions and 3 deletions

View File

@@ -164,6 +164,26 @@ export const useExportLayers = (layersRef: Ref<Layer[]>, columns: Ref<number>, 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;
});

View File

@@ -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);