From cf43efe3ee6cb0ba7377c61607f8977cc0d93022 Mon Sep 17 00:00:00 2001 From: griffpatch Date: Fri, 27 Jan 2017 11:14:53 +0000 Subject: [PATCH 1/4] Effect not correctly copied to clones #337 Fixes Effect not correctly copied to clones #337 --- src/sprites/rendered-target.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 36affd7b1..9eb8956b2 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -437,7 +437,7 @@ RenderedTarget.prototype.updateAllDrawableProperties = function () { if (this.renderer) { var renderedDirectionScale = this._getRenderedDirectionAndScale(); var costume = this.sprite.costumes[this.currentCostume]; - this.renderer.updateDrawableProperties(this.drawableID, { + var props = { position: [this.x, this.y], direction: renderedDirectionScale.direction, scale: renderedDirectionScale.scale, @@ -448,7 +448,11 @@ RenderedTarget.prototype.updateAllDrawableProperties = function () { costume.rotationCenterX / costume.bitmapResolution, costume.rotationCenterY / costume.bitmapResolution ] - }); + }; + for (var effectID in this.effects) { + props[effectID] = this.effects[effectID]; + } + this.renderer.updateDrawableProperties(this.drawableID, props); if (this.visible) { this.runtime.requestRedraw(); } From 2ac4b73a1f966d74a9328299a85908978a4419e2 Mon Sep 17 00:00:00 2001 From: griffpatch Date: Fri, 27 Jan 2017 10:16:19 +0000 Subject: [PATCH 2/4] Importers: adjust block coordinate calculation so blocks overlap less. #326 This change imports the scratch blocks much closer to the Scratch 2 spacing. --- src/import/sb2import.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/import/sb2import.js b/src/import/sb2import.js index 92600ed65..96009abb8 100644 --- a/src/import/sb2import.js +++ b/src/import/sb2import.js @@ -166,8 +166,8 @@ var parseScripts = function (scripts, blocks) { // Adjust script coordinates to account for // larger block size in scratch-blocks. // @todo: Determine more precisely the right formulas here. - parsedBlockList[0].x = scriptX * 1.1; - parsedBlockList[0].y = scriptY * 1.1; + parsedBlockList[0].x = scriptX * 1.5; + parsedBlockList[0].y = scriptY * 2.2; parsedBlockList[0].topLevel = true; parsedBlockList[0].parent = null; } From b856041d9a3f7dfbdf835965312708dfb63e7b3e Mon Sep 17 00:00:00 2001 From: griffpatch Date: Fri, 27 Jan 2017 12:49:32 +0000 Subject: [PATCH 3/4] Fix for Support ARGB for pen #393 Requires fix to scratch-render before this will work (see: 6f5acfee7b961d71237f1fd50bb3d5a5139c527e) --- src/blocks/scratch3_pen.js | 3 +++ src/util/color.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/blocks/scratch3_pen.js b/src/blocks/scratch3_pen.js index 5d652531b..e8a29965f 100644 --- a/src/blocks/scratch3_pen.js +++ b/src/blocks/scratch3_pen.js @@ -258,6 +258,9 @@ Scratch3PenBlocks.prototype.setPenColorToColor = function (args, util) { penState.penAttributes.color4f[0] = rgb.r / 255.0; penState.penAttributes.color4f[1] = rgb.g / 255.0; penState.penAttributes.color4f[2] = rgb.b / 255.0; + if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'? + penState.penAttributes.color4f[3] = rgb.a/255.0; + } }; /** diff --git a/src/util/color.js b/src/util/color.js index 951cb270a..b0ea899ca 100644 --- a/src/util/color.js +++ b/src/util/color.js @@ -40,10 +40,11 @@ Color.decimalToHex = function (decimal) { * @return {RGBObject} rgb - {r: red [0,255], g: green [0,255], b: blue [0,255]}. */ Color.decimalToRgb = function (decimal) { + var a = (decimal >> 24) & 0xFF; var r = (decimal >> 16) & 0xFF; var g = (decimal >> 8) & 0xFF; var b = decimal & 0xFF; - return {r: r, g: g, b: b}; + return {r: r, g: g, b: b, a: a>0 ? a : 255}; }; /** From 0dcaa46107559360af39e9bc14d8963f2d7ad838 Mon Sep 17 00:00:00 2001 From: griffpatch Date: Fri, 27 Jan 2017 17:05:17 +0000 Subject: [PATCH 4/4] Fix lint issues Had to update the test scripts to handle the alpha channel, also I note that all the hex tests are using CSS notation, not scratch notation (which is 0x not #) --- src/blocks/scratch3_pen.js | 2 +- src/util/color.js | 2 +- test/unit/util_cast.js | 11 ++++++----- test/unit/util_color.js | 10 +++++----- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/blocks/scratch3_pen.js b/src/blocks/scratch3_pen.js index e8a29965f..6ef00cf71 100644 --- a/src/blocks/scratch3_pen.js +++ b/src/blocks/scratch3_pen.js @@ -259,7 +259,7 @@ Scratch3PenBlocks.prototype.setPenColorToColor = function (args, util) { penState.penAttributes.color4f[1] = rgb.g / 255.0; penState.penAttributes.color4f[2] = rgb.b / 255.0; if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'? - penState.penAttributes.color4f[3] = rgb.a/255.0; + penState.penAttributes.color4f[3] = rgb.a / 255.0; } }; diff --git a/src/util/color.js b/src/util/color.js index b0ea899ca..11082d660 100644 --- a/src/util/color.js +++ b/src/util/color.js @@ -44,7 +44,7 @@ Color.decimalToRgb = function (decimal) { var r = (decimal >> 16) & 0xFF; var g = (decimal >> 8) & 0xFF; var b = decimal & 0xFF; - return {r: r, g: g, b: b, a: a>0 ? a : 255}; + return {r: r, g: g, b: b, a: a > 0 ? a : 255}; }; /** diff --git a/test/unit/util_cast.js b/test/unit/util_cast.js index 4f15d16bb..861373bb2 100644 --- a/test/unit/util_cast.js +++ b/test/unit/util_cast.js @@ -99,13 +99,14 @@ test('toRbgColorObject', function (t) { t.deepEqual(cast.toRgbColorObject('#ffffff'), {r: 255, g: 255, b: 255}); // Decimal (minimal, see "color" util tests) - t.deepEqual(cast.toRgbColorObject(0), {r: 0, g: 0, b: 0}); - t.deepEqual(cast.toRgbColorObject(1), {r: 0, g: 0, b: 1}); - t.deepEqual(cast.toRgbColorObject(16777215), {r: 255, g: 255, b: 255}); + t.deepEqual(cast.toRgbColorObject(0), {a: 255, r: 0, g: 0, b: 0}); + t.deepEqual(cast.toRgbColorObject(1), {a: 255, r: 0, g: 0, b: 1}); + t.deepEqual(cast.toRgbColorObject(16777215), {a: 255, r: 255, g: 255, b: 255}); + t.deepEqual(cast.toRgbColorObject('0x80010203'), {a: 128, r: 1, g: 2, b: 3}); // Malformed - t.deepEqual(cast.toRgbColorObject('ffffff'), {r: 0, g: 0, b: 0}); - t.deepEqual(cast.toRgbColorObject('foobar'), {r: 0, g: 0, b: 0}); + t.deepEqual(cast.toRgbColorObject('ffffff'), {a: 255, r: 0, g: 0, b: 0}); + t.deepEqual(cast.toRgbColorObject('foobar'), {a: 255, r: 0, g: 0, b: 0}); t.end(); }); diff --git a/test/unit/util_color.js b/test/unit/util_color.js index 1ffb737eb..ea68b786d 100644 --- a/test/unit/util_color.js +++ b/test/unit/util_color.js @@ -47,11 +47,11 @@ test('decimalToHex', function (t) { }); test('decimalToRgb', function (t) { - t.deepEqual(color.decimalToRgb(0), {r: 0, g: 0, b: 0}); - t.deepEqual(color.decimalToRgb(1), {r: 0, g: 0, b: 1}); - t.deepEqual(color.decimalToRgb(16777215), {r: 255, g: 255, b: 255}); - t.deepEqual(color.decimalToRgb(-16777215), {r: 0, g: 0, b: 1}); - t.deepEqual(color.decimalToRgb(99999999), {r: 245, g: 224, b: 255}); + t.deepEqual(color.decimalToRgb(0), {a: 255, r: 0, g: 0, b: 0}); + t.deepEqual(color.decimalToRgb(1), {a: 255, r: 0, g: 0, b: 1}); + t.deepEqual(color.decimalToRgb(16777215), {a: 255, r: 255, g: 255, b: 255}); + t.deepEqual(color.decimalToRgb(-16777215), {a: 255, r: 0, g: 0, b: 1}); + t.deepEqual(color.decimalToRgb(99999999), {a: 5, r: 245, g: 224, b: 255}); t.end(); });