From ada7dba959bdc3e6567c587fe6fa5dfcb0e23cb6 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Mon, 9 Dec 2024 18:29:20 +0100 Subject: [PATCH] Fix installing assets with resource kinds like bitmap texts (#7222) --- newIDE/app/src/AssetStore/InstallAsset.js | 26 ++++++----------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/newIDE/app/src/AssetStore/InstallAsset.js b/newIDE/app/src/AssetStore/InstallAsset.js index bbf9809d462f..9fb08f06e56d 100644 --- a/newIDE/app/src/AssetStore/InstallAsset.js +++ b/newIDE/app/src/AssetStore/InstallAsset.js @@ -20,6 +20,7 @@ import { type EventsFunctionsExtensionsState } from '../EventsFunctionsExtension import { mapVector } from '../Utils/MapFor'; import { toNewGdMapStringString } from '../Utils/MapStringString'; import { getInsertionParentAndPositionFromSelection } from '../Utils/ObjectFolders'; +import { allResourceKindsAndMetadata } from '../ResourcesList/ResourceSource'; const gd: libGDevelop = global.gd; @@ -110,30 +111,17 @@ export const installResource = ( return; } - // The resource does not exist yet, add it. Note that the "origin" will be preserved. - let newResource = null; - if (serializedResource.kind === 'image') { - newResource = new gd.ImageResource(); - } else if (serializedResource.kind === 'audio') { - newResource = new gd.AudioResource(); - } else if (serializedResource.kind === 'font') { - newResource = new gd.FontResource(); - } else if (serializedResource.kind === 'video') { - newResource = new gd.VideoResource(); - } else if (serializedResource.kind === 'json') { - newResource = new gd.JsonResource(); - } else if (serializedResource.kind === 'model3D') { - newResource = new gd.Model3DResource(); - } else if (serializedResource.kind === 'atlas') { - newResource = new gd.AtlasResource(); - } else if (serializedResource.kind === 'spine') { - newResource = new gd.SpineResource(); - } else { + const resourceKindMetadata = allResourceKindsAndMetadata.find( + resourceKind => resourceKind.kind === serializedResource.kind + ); + if (!resourceKindMetadata) { throw new Error( `Resource of kind "${serializedResource.kind}" is not supported.` ); } + // The resource does not exist yet, add it. Note that the "origin" will be preserved. + const newResource = resourceKindMetadata.createNewResource(); unserializeFromJSObject(newResource, serializedResource); if (newResource.getKind() === 'image') {