From a434bc5a34aab005a9fee16883725ba18a6af134 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Thu, 30 Jan 2020 00:03:42 -0500 Subject: [PATCH 1/3] Remove calls to updateDrawableSkinIdRotationCenter --- src/import/load-costume.js | 13 +++++++++++-- src/sprites/rendered-target.js | 20 ++------------------ test/fixtures/fake-renderer.js | 3 --- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/import/load-costume.js b/src/import/load-costume.js index 6dcb3ff9954..79bb5f12149 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -212,8 +212,17 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) { return fetched; }) .then(({canvas, mergeCanvas, rotationCenter}) => { - // createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined... - costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, rotationCenter); + // createBitmapSkin does the right thing if costume.bitmapResolution is undefined... + // TODO: is rotationCenter ever undefined? + let center; + if (rotationCenter) { + center = [ + rotationCenter[0] / 2, + rotationCenter[1] / 2 + ]; + } + + costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, center); canvasPool.release(mergeCanvas); const renderSize = runtime.renderer.getSkinSize(costume.skinId); costume.size = [renderSize[0] * 2, renderSize[1] * 2]; // Actual size, since all bitmaps are resolution 2 diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 018f7cd16bb..40b774fb29d 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -458,19 +458,7 @@ class RenderedTarget extends Target { ); if (this.renderer) { const costume = this.getCostumes()[this.currentCostume]; - if ( - typeof costume.rotationCenterX !== 'undefined' && - typeof costume.rotationCenterY !== 'undefined' - ) { - const scale = costume.bitmapResolution || 2; - const rotationCenter = [ - costume.rotationCenterX / scale, - costume.rotationCenterY / scale - ]; - this.renderer.updateDrawableSkinIdRotationCenter(this.drawableID, costume.skinId, rotationCenter); - } else { - this.renderer.updateDrawableSkinId(this.drawableID, costume.skinId); - } + this.renderer.updateDrawableSkinId(this.drawableID, costume.skinId); if (this.visible) { this.emit(RenderedTarget.EVENT_TARGET_VISUAL_CHANGE, this); @@ -709,11 +697,7 @@ class RenderedTarget extends Target { this.renderer.updateDrawableVisible(this.drawableID, this.visible); const costume = this.getCostumes()[this.currentCostume]; - const bitmapResolution = costume.bitmapResolution || 2; - this.renderer.updateDrawableSkinIdRotationCenter(this.drawableID, costume.skinId, [ - costume.rotationCenterX / bitmapResolution, - costume.rotationCenterY / bitmapResolution - ]); + this.renderer.updateDrawableSkinId(this.drawableID, costume.skinId); for (const effectName in this.effects) { if (!this.effects.hasOwnProperty(effectName)) continue; diff --git a/test/fixtures/fake-renderer.js b/test/fixtures/fake-renderer.js index 73b37ede6e8..41ffa7b1c3e 100644 --- a/test/fixtures/fake-renderer.js +++ b/test/fixtures/fake-renderer.js @@ -17,9 +17,6 @@ FakeRenderer.prototype.getFencedPositionOfDrawable = function (d, p) { // eslint FakeRenderer.prototype.updateDrawableSkinId = function (d, skinId) { // eslint-disable-line no-unused-vars }; -FakeRenderer.prototype.updateDrawableSkinIdRotationCenter = - function (d, skinId, rotationCenter) {}; // eslint-disable-line no-unused-vars - FakeRenderer.prototype.updateDrawablePosition = function (d, position) { // eslint-disable-line no-unused-vars this.x = position[0]; this.y = position[1]; From 5387f3a72938d1cee5a63db56868d1c2eed4f170 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Thu, 26 Mar 2020 23:12:10 -0400 Subject: [PATCH 2/3] Clarify loadBitmap_ comments --- src/import/load-costume.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/import/load-costume.js b/src/import/load-costume.js index 79bb5f12149..1524a6d0eff 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -212,16 +212,20 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) { return fetched; }) .then(({canvas, mergeCanvas, rotationCenter}) => { - // createBitmapSkin does the right thing if costume.bitmapResolution is undefined... - // TODO: is rotationCenter ever undefined? + // createBitmapSkin does the right thing if costume.rotationCenter are undefined. + // That will be the case if you upload a bitmap asset or create one by taking a photo. let center; if (rotationCenter) { + // fetchBitmapCanvas will ensure that the costume's bitmap resolution is 2 and its rotation center is + // scaled to match, so it's okay to always divide by 2. center = [ rotationCenter[0] / 2, rotationCenter[1] / 2 ]; } + // TODO: costume.bitmapResolution will always be 2 at this point because of fetchBitmapCanvas_, so we don't + // need to pass it in here. costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, center); canvasPool.release(mergeCanvas); const renderSize = runtime.renderer.getSkinSize(costume.skinId); From c30fcd23b5f12e8c3533c5980f842b4c58b6200f Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sat, 28 Mar 2020 01:07:14 -0400 Subject: [PATCH 3/3] grammar --- src/import/load-costume.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/import/load-costume.js b/src/import/load-costume.js index 1524a6d0eff..2db12e13b0b 100644 --- a/src/import/load-costume.js +++ b/src/import/load-costume.js @@ -212,7 +212,7 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) { return fetched; }) .then(({canvas, mergeCanvas, rotationCenter}) => { - // createBitmapSkin does the right thing if costume.rotationCenter are undefined. + // createBitmapSkin does the right thing if costume.rotationCenter is undefined. // That will be the case if you upload a bitmap asset or create one by taking a photo. let center; if (rotationCenter) {