From a4b055001379173f8df4bde54060d0a92bc850a5 Mon Sep 17 00:00:00 2001 From: chrisgarrity Date: Fri, 8 Feb 2019 15:03:27 +0100 Subject: [PATCH] handle sb2 files zipped in a folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the asset can’t be found by name, look for the same asset in a folder within the zipfile. --- src/serialization/deserialize-assets.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/serialization/deserialize-assets.js b/src/serialization/deserialize-assets.js index be48db12b..bf59f915f 100644 --- a/src/serialization/deserialize-assets.js +++ b/src/serialization/deserialize-assets.js @@ -26,7 +26,13 @@ const deserializeSound = function (sound, runtime, zip, assetFileName) { return Promise.resolve(null); } - const soundFile = zip.file(fileName); + let soundFile = zip.file(fileName); + if (!soundFile) { + // look for assetfile in a flat list of files, or in a folder + const fileMatch = new RegExp(`^([^/]*/)?${fileName}$`); + soundFile = zip.file(fileMatch)[0]; // use first matching file + } + if (!soundFile) { log.error(`Could not find sound file associated with the ${sound.name} sound.`); return Promise.resolve(null); @@ -100,7 +106,13 @@ const deserializeCostume = function (costume, runtime, zip, assetFileName, textL return Promise.resolve(null); } - const costumeFile = zip.file(fileName); + let costumeFile = zip.file(fileName); + if (!costumeFile) { + // look for assetfile in a flat list of files, or in a folder + const fileMatch = new RegExp(`^([^/]*/)?${fileName}$`); + costumeFile = zip.file(fileMatch)[0]; // use the first matched file + } + if (!costumeFile) { log.error(`Could not find costume file associated with the ${costume.name} costume.`); return Promise.resolve(null);