Correct what is being passed into scratch-render if some metadata (rotationCenter, bitmapResolution) is missing.

This commit is contained in:
Karishma Chadha 2018-04-18 14:21:29 -04:00
parent 47a2d76a14
commit d6f28f2266

View file

@ -20,11 +20,16 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
return costume; return costume;
} }
const AssetType = runtime.storage.AssetType; const AssetType = runtime.storage.AssetType;
const rotationCenter = [ let rotationCenter;
if (costume.rotationCenterX && costume.rotationCenterY && costume.bitmapResolution) {
rotationCenter = [
costume.rotationCenterX / costume.bitmapResolution, costume.rotationCenterX / costume.bitmapResolution,
costume.rotationCenterY / costume.bitmapResolution costume.rotationCenterY / costume.bitmapResolution
]; ];
}
if (costumeAsset.assetType === AssetType.ImageVector) { if (costumeAsset.assetType === AssetType.ImageVector) {
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
// undefined here
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter); costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
costume.size = runtime.renderer.getSkinSize(costume.skinId); costume.size = runtime.renderer.getSkinSize(costume.skinId);
return costume; return costume;
@ -50,6 +55,7 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
imageElement.addEventListener('load', onLoad); imageElement.addEventListener('load', onLoad);
imageElement.src = costumeAsset.encodeDataURI(); imageElement.src = costumeAsset.encodeDataURI();
}).then(imageElement => { }).then(imageElement => {
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter); costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
costume.size = runtime.renderer.getSkinSize(costume.skinId); costume.size = runtime.renderer.getSkinSize(costume.skinId);
return costume; return costume;