Merge pull request from kchadha/load-costume-no-metadata

Load costume without metadata
This commit is contained in:
kchadha 2018-04-23 17:52:04 -04:00 committed by GitHub
commit cde801bc17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 11 deletions

View file

@ -15,18 +15,31 @@ 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;
}
const AssetType = runtime.storage.AssetType;
const rotationCenter = [
costume.rotationCenterX / costume.bitmapResolution,
costume.rotationCenterY / costume.bitmapResolution
];
let rotationCenter;
if (costume.rotationCenterX && costume.rotationCenterY && costume.bitmapResolution) {
rotationCenter = [
costume.rotationCenterX / costume.bitmapResolution,
costume.rotationCenterY / costume.bitmapResolution
];
}
if (costumeAsset.assetType === AssetType.ImageVector) {
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
costume.size = runtime.renderer.getSkinSize(costume.skinId);
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
// undefined here
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;
}
@ -50,8 +63,15 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
imageElement.addEventListener('load', onLoad);
imageElement.src = costumeAsset.encodeDataURI();
}).then(imageElement => {
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
costume.size = runtime.renderer.getSkinSize(costume.skinId);
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
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] * 2;
costume.rotationCenterY = rotationCenter[1] * 2;
}
return costume;
});
};

View file

@ -452,7 +452,7 @@ class RenderedTarget extends Target {
typeof costume.rotationCenterX !== 'undefined' &&
typeof costume.rotationCenterY !== 'undefined'
) {
const scale = costume.bitmapResolution || 1;
const scale = costume.bitmapResolution || 2;
drawableProperties.rotationCenter = [
costume.rotationCenterX / scale,
costume.rotationCenterY / scale
@ -641,7 +641,7 @@ class RenderedTarget extends Target {
if (this.renderer) {
const renderedDirectionScale = this._getRenderedDirectionAndScale();
const costume = this.getCostumes()[this.currentCostume];
const bitmapResolution = costume.bitmapResolution || 1;
const bitmapResolution = costume.bitmapResolution || 2;
const props = {
position: [this.x, this.y],
direction: renderedDirectionScale.direction,