Load text layer asset

This commit is contained in:
DD 2018-11-06 10:36:52 -05:00
parent 88b6bdd06c
commit b6b3ca21d7

View file

@ -153,7 +153,11 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime, optVersio
*/ */
const loadCostume = function (md5ext, costume, runtime, optVersion) { const loadCostume = function (md5ext, costume, runtime, optVersion) {
let costumePromise; let costumePromise;
let textLayerPromise;
if (costume.asset) { if (costume.asset) {
// TODO if text asset exists, merge the 2 assets, put it back in storage, clean up text layer
// data from costume and return the costume with merged asset here.
// Costume comes with asset. It could be coming from camera, image upload, drag and drop, or sb file // Costume comes with asset. It could be coming from camera, image upload, drag and drop, or sb file
costumePromise = Promise.resolve(costume.asset); costumePromise = Promise.resolve(costume.asset);
} else { } else {
@ -174,10 +178,19 @@ const loadCostume = function (md5ext, costume, runtime, optVersion) {
log.error(`Couldn't fetch costume asset: ${md5ext}`); log.error(`Couldn't fetch costume asset: ${md5ext}`);
return; return;
} }
if (costume.textLayerMD5) {
textLayerPromise = runtime.storage.load(AssetType.ImageBitmap, costume.textLayerMD5, 'png');
} else {
textLayerPromise = Promise.resolve(null);
}
} }
return costumePromise.then(costumeAsset => { return Promise.all(costumePromise, textLayerPromise).then(assetArray => {
costume.asset = costumeAsset; costume.asset = assetArray[0];
if (assetArray[1]) {
costume.textLayerAsset = assetArray[1];
}
return loadCostumeFromAsset(costume, costumeAsset, runtime, optVersion); return loadCostumeFromAsset(costume, costumeAsset, runtime, optVersion);
}) })
.catch(e => { .catch(e => {