Skip to content

Commit ada7dba

Browse files
authored
Fix installing assets with resource kinds like bitmap texts (#7222)
1 parent 1b0c088 commit ada7dba

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

newIDE/app/src/AssetStore/InstallAsset.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { type EventsFunctionsExtensionsState } from '../EventsFunctionsExtension
2020
import { mapVector } from '../Utils/MapFor';
2121
import { toNewGdMapStringString } from '../Utils/MapStringString';
2222
import { getInsertionParentAndPositionFromSelection } from '../Utils/ObjectFolders';
23+
import { allResourceKindsAndMetadata } from '../ResourcesList/ResourceSource';
2324

2425
const gd: libGDevelop = global.gd;
2526

@@ -110,30 +111,17 @@ export const installResource = (
110111
return;
111112
}
112113

113-
// The resource does not exist yet, add it. Note that the "origin" will be preserved.
114-
let newResource = null;
115-
if (serializedResource.kind === 'image') {
116-
newResource = new gd.ImageResource();
117-
} else if (serializedResource.kind === 'audio') {
118-
newResource = new gd.AudioResource();
119-
} else if (serializedResource.kind === 'font') {
120-
newResource = new gd.FontResource();
121-
} else if (serializedResource.kind === 'video') {
122-
newResource = new gd.VideoResource();
123-
} else if (serializedResource.kind === 'json') {
124-
newResource = new gd.JsonResource();
125-
} else if (serializedResource.kind === 'model3D') {
126-
newResource = new gd.Model3DResource();
127-
} else if (serializedResource.kind === 'atlas') {
128-
newResource = new gd.AtlasResource();
129-
} else if (serializedResource.kind === 'spine') {
130-
newResource = new gd.SpineResource();
131-
} else {
114+
const resourceKindMetadata = allResourceKindsAndMetadata.find(
115+
resourceKind => resourceKind.kind === serializedResource.kind
116+
);
117+
if (!resourceKindMetadata) {
132118
throw new Error(
133119
`Resource of kind "${serializedResource.kind}" is not supported.`
134120
);
135121
}
136122

123+
// The resource does not exist yet, add it. Note that the "origin" will be preserved.
124+
const newResource = resourceKindMetadata.createNewResource();
137125
unserializeFromJSObject(newResource, serializedResource);
138126

139127
if (newResource.getKind() === 'image') {

0 commit comments

Comments
 (0)