From f29482957c8c8db185301cf5e33745bf558e9a3a Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 10 Apr 2018 09:50:18 -0400 Subject: [PATCH 1/2] Change getSkinSize to getCurrentSkinSize for renderer update. --- src/blocks/scratch3_looks.js | 2 +- src/sprites/rendered-target.js | 2 +- test/fixtures/fake-renderer.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 949095f33..e04c5cc15 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -118,7 +118,7 @@ class Scratch3LooksBlocks { */ _positionBubble (target) { const bubbleState = this._getBubbleState(target); - const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getSkinSize(bubbleState.drawableId); + const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getCurrentSkinSize(bubbleState.drawableId); const targetBounds = target.getBoundsForBubble(); const stageBounds = this.runtime.getTargetForStage().getBounds(); if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right && diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 35204ec93..7032a47de 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -355,7 +355,7 @@ class RenderedTarget extends Target { if (this.renderer) { // Clamp to scales relative to costume and stage size. // See original ScratchSprite.as:setSize. - const costumeSize = this.renderer.getSkinSize(this.drawableID); + const costumeSize = this.renderer.getCurrentSkinSize(this.drawableID); const origW = costumeSize[0]; const origH = costumeSize[1]; const minScale = Math.min(1, Math.max(5 / origW, 5 / origH)); diff --git a/test/fixtures/fake-renderer.js b/test/fixtures/fake-renderer.js index a6cc9fc32..a5fc2fb8f 100644 --- a/test/fixtures/fake-renderer.js +++ b/test/fixtures/fake-renderer.js @@ -22,7 +22,7 @@ FakeRenderer.prototype.updateDrawableProperties = function (d, p) { // eslint-di return true; }; -FakeRenderer.prototype.getSkinSize = function (d) { // eslint-disable-line no-unused-vars +FakeRenderer.prototype.getCurrentSkinSize = function (d) { // eslint-disable-line no-unused-vars return [0, 0]; }; From 89eb1ce39b25a49f22a33aeabd3cc9124fa26e9d Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 10 Apr 2018 09:51:29 -0400 Subject: [PATCH 2/2] Set the costume asset size when a costume is loaded or modified. --- src/import/load-costume.js | 2 ++ src/virtual-machine.js | 1 + 2 files changed, 3 insertions(+) diff --git a/src/import/load-costume.js b/src/import/load-costume.js index a355edddc..e94e1c917 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -26,6 +26,7 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) { ]; if (costumeAsset.assetType === AssetType.ImageVector) { costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter); + costume.size = runtime.renderer.getSkinSize(costume.skinId); return costume; } @@ -50,6 +51,7 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) { imageElement.src = costumeAsset.encodeDataURI(); }).then(imageElement => { costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter); + costume.size = runtime.renderer.getSkinSize(costume.skinId); return costume; }); }; diff --git a/src/virtual-machine.js b/src/virtual-machine.js index abe4b69ba..b9d351f8e 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -541,6 +541,7 @@ class VirtualMachine extends EventEmitter { costume.rotationCenterX = rotationCenterX; costume.rotationCenterY = rotationCenterY; this.runtime.renderer.updateSVGSkin(costume.skinId, svg, [rotationCenterX, rotationCenterY]); + costume.size = this.runtime.renderer.getSkinSize(costume.skinId); } const storage = this.runtime.storage; costume.assetId = storage.builtinHelper.cache(