Add costume dataURI to costumes from storage ()

* Add costume dataURI to costumes from storage

Towards , 

* Fix tests

* Load costumes incrementally

Some of our tests assume that at least some of our costume data is available before the costume data is loaded. So, provide as much costume data as is available.

* Remove unnecessary filter for null costumes

Resolved when we updated to load costumes incrementally.

/ht @cwillisf
This commit is contained in:
Ray Schamp 2017-04-03 15:58:13 -04:00 committed by GitHub
parent a4aa3810ae
commit 57e73a68a6
3 changed files with 39 additions and 27 deletions
src/import
test/integration

View file

@ -16,13 +16,9 @@ var log = require('../util/log');
var loadCostume = function (md5ext, costume, runtime) { var loadCostume = function (md5ext, costume, runtime) {
if (!runtime.storage) { if (!runtime.storage) {
log.error('No storage module present; cannot load costume asset: ', md5ext); log.error('No storage module present; cannot load costume asset: ', md5ext);
return Promise.resolve(null); return Promise.resolve(costume);
} }
if (!runtime.renderer) {
log.error('No rendering module present; cannot load costume asset: ', md5ext);
return Promise.resolve(null);
}
var idParts = md5ext.split('.'); var idParts = md5ext.split('.');
var md5 = idParts[0]; var md5 = idParts[0];
@ -34,11 +30,22 @@ var loadCostume = function (md5ext, costume, runtime) {
costume.rotationCenterY / costume.bitmapResolution costume.rotationCenterY / costume.bitmapResolution
]; ];
var promise = runtime.storage.load(assetType, md5); var promise = runtime.storage.load(assetType, md5).then(function (costumeAsset) {
costume.url = costumeAsset.encodeDataURI();
return costumeAsset;
});
if (!runtime.renderer) {
log.error('No rendering module present; cannot load costume asset: ', md5ext);
return promise.then(function () {
return costume;
});
}
if (assetType === AssetType.ImageVector) { if (assetType === AssetType.ImageVector) {
promise = promise.then(function (costumeAsset) { promise = promise.then(function (costumeAsset) {
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter); costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
return costume;
}); });
} else { } else {
promise = promise.then(function (costumeAsset) { promise = promise.then(function (costumeAsset) {
@ -63,6 +70,7 @@ var loadCostume = function (md5ext, costume, runtime) {
}); });
}).then(function (imageElement) { }).then(function (imageElement) {
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter); costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
return costume;
}); });
} }
return promise; return promise;

View file

@ -53,11 +53,8 @@ var parseScratchObject = function (object, runtime, topLevel) {
rotationCenterY: costumeSource.rotationCenterY, rotationCenterY: costumeSource.rotationCenterY,
skinId: null skinId: null
}; };
var costumePromise = loadCostume(costumeSource.baseLayerMD5, costume, runtime);
if (costumePromise) {
costumePromises.push(costumePromise);
}
sprite.costumes.push(costume); sprite.costumes.push(costume);
costumePromises.push(loadCostume(costumeSource.baseLayerMD5, costume, runtime));
} }
} }
// Sounds from JSON // Sounds from JSON
@ -138,7 +135,8 @@ var parseScratchObject = function (object, runtime, topLevel) {
} }
} }
target.isStage = topLevel; target.isStage = topLevel;
Promise.all(costumePromises).then(function () { Promise.all(costumePromises).then(function (costumes) {
sprite.costumes = costumes;
target.updateAllDrawableProperties(); target.updateAllDrawableProperties();
}); });
// The stage will have child objects; recursively process them. // The stage will have child objects; recursively process them.

View file

@ -40,14 +40,17 @@ test('complex', function (t) {
rotationStyle: 'all around', rotationStyle: 'all around',
visible: true visible: true
}); });
vm.addCostume({ vm.addCostume(
costumeName: 'costume1', 'f9a1c175dbe2e5dee472858dd30d16bb.svg',
baseLayerID: 0, {
baseLayerMD5: 'f9a1c175dbe2e5dee472858dd30d16bb.svg', costumeName: 'costume1',
bitmapResolution: 1, baseLayerID: 0,
rotationCenterX: 47, baseLayerMD5: 'f9a1c175dbe2e5dee472858dd30d16bb.svg',
rotationCenterY: 55 bitmapResolution: 1,
}); rotationCenterX: 47,
rotationCenterY: 55
}
);
} }
}); });
@ -73,14 +76,17 @@ test('complex', function (t) {
vm.addSprite2(sprite); vm.addSprite2(sprite);
// Add backdrop // Add backdrop
vm.addBackdrop({ vm.addBackdrop(
costumeName: 'baseball-field', '6b3d87ba2a7f89be703163b6c1d4c964.png',
baseLayerID: 26, {
baseLayerMD5: '6b3d87ba2a7f89be703163b6c1d4c964.png', costumeName: 'baseball-field',
bitmapResolution: 2, baseLayerID: 26,
rotationCenterX: 480, baseLayerMD5: '6b3d87ba2a7f89be703163b6c1d4c964.png',
rotationCenterY: 360 bitmapResolution: 2,
}); rotationCenterX: 480,
rotationCenterY: 360
}
);
}); });
// After two seconds, get playground data and stop // After two seconds, get playground data and stop