diff --git a/src/import/load-costume.js b/src/import/load-costume.js index 900c25ae3..64a131f69 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -15,7 +15,8 @@ const log = require('../util/log'); */ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) { costume.assetId = costumeAsset.assetId; - if (!runtime.renderer) { + const renderer = runtime.renderer; + if (!renderer) { log.error('No rendering module present; cannot load costume: ', costume.name); return costume; } @@ -30,8 +31,15 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) { 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.size = runtime.renderer.getSkinSize(costume.skinId); + costume.skinId = renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter); + costume.size = renderer.getSkinSize(costume.skinId); + // Now we should have a rotationCenter even if we didn't before + if (!rotationCenter) { + rotationCenter = renderer.getSkinRotationCenter(costume.skinId); + costume.rotationCenterX = rotationCenter[0]; + costume.rotationCenterY = rotationCenter[1]; + } + return costume; } @@ -56,8 +64,14 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) { imageElement.src = costumeAsset.encodeDataURI(); }).then(imageElement => { // createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined... - costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter); - costume.size = runtime.renderer.getSkinSize(costume.skinId); + costume.skinId = renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter); + costume.size = renderer.getSkinSize(costume.skinId); + + if (!rotationCenter) { + rotationCenter = renderer.getSkinRotationCenter(costume.skinId); + costume.rotationCenterX = rotationCenter[0]; + costume.rotationCenterY = rotationCenter[1]; + } return costume; }); }; diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 696bbae35..1f70d81a7 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -405,8 +405,8 @@ class VirtualMachine extends EventEmitter { * @returns {?Promise} - a promise that resolves when the costume has been added */ addCostume (md5ext, costumeObject) { - return loadCostume(md5ext, costumeObject, this.runtime).then(() => { - this.editingTarget.addCostume(costumeObject); + return loadCostume(md5ext, costumeObject, this.runtime).then(loadedCostume => { + this.editingTarget.addCostume(loadedCostume); this.editingTarget.setCostume( this.editingTarget.getCostumes().length - 1 );