Skip to content

Commit

Permalink
🐛 Fix repeated import of same-named images (or the same image) leadin…
Browse files Browse the repository at this point in the history
…g to textures with identical names, which broke exports
  • Loading branch information
CosmoMyzrailGorynych committed Sep 19, 2024
1 parent 20d4473 commit 450702d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/node_requires/resources/textures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ const importImageToTexture = async (opts: {
};
image.src = 'file://' + dest + '?' + Math.random();
});
let texName;
let texName: string;
if (opts.name) {
texName = opts.name;
} else if (opts.src instanceof Buffer) {
Expand All @@ -292,6 +292,15 @@ const importImageToTexture = async (opts: {
.replace(/\.(jpg|gif|png|jpeg)/gi, '')
.replace(/\s/g, '_');
}
// Avoid name duplicates
const baseName = texName;
const textures = getOfType('texture');
let texPostfix = 2;
// eslint-disable-next-line no-loop-func
while (textures.some(t => t.name === texName)) {
texName = `${baseName}_${texPostfix}`;
texPostfix++;
}
const obj: ITexture = {
lastmod: Number(new Date()),
type: 'texture',
Expand Down

0 comments on commit 450702d

Please sign in to comment.