From 404834018bcbcffd3fc97d5b140206950424b81c Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 9 Jun 2018 21:34:21 -0300 Subject: [PATCH 1/4] Implement costume name block --- src/blocks/scratch3_looks.js | 6 ++++++ src/serialization/sb2_specmap.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 4a7994a4a..487e61389 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -252,6 +252,7 @@ class Scratch3LooksBlocks { looks_goforwardbackwardlayers: this.goForwardBackwardLayers, looks_size: this.getSize, looks_costumenumbername: this.getCostumeNumberName, + looks_costumename: this.getCostumeName, looks_backdropnumbername: this.getBackdropNumberName }; } @@ -488,6 +489,11 @@ class Scratch3LooksBlocks { // Else return name return util.target.getCostumes()[util.target.currentCostume].name; } + + getCostumeName (args, util) { + // Obsolete block from earlier Scratch versions. + return util.target.getCostumes()[util.target.currentCostume].name; + } } module.exports = Scratch3LooksBlocks; diff --git a/src/serialization/sb2_specmap.js b/src/serialization/sb2_specmap.js index e22025285..44dc41bdd 100644 --- a/src/serialization/sb2_specmap.js +++ b/src/serialization/sb2_specmap.js @@ -428,6 +428,11 @@ const specMap = { argMap: [ ] }, + 'costumeName': { + opcode: 'looks_costumename', + argMap: [ + ] + }, 'sceneName': { opcode: 'looks_backdropnumbername', argMap: [ From 93d6b237724d9bed2da26a333d79a5873a1db7e3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 9 Jun 2018 21:52:46 -0300 Subject: [PATCH 2/4] Test for getCostumeName --- test/unit/blocks_looks.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/unit/blocks_looks.js b/test/unit/blocks_looks.js index c7b4c3d7b..e5d0ab2ff 100644 --- a/test/unit/blocks_looks.js +++ b/test/unit/blocks_looks.js @@ -34,8 +34,15 @@ test('getCostumeNumberName returns 1-indexed costume number', t => { test('getCostumeNumberName can return costume name', t => { util.target.currentCostume = 0; // This is 0-indexed. const args = {NUMBER_NAME: 'name'}; - const number = blocks.getCostumeNumberName(args, util); - t.strictEqual(number, 'first name'); + const name = blocks.getCostumeNumberName(args, util); + t.strictEqual(name, 'first name'); + t.end(); +}); + +test('getCostumeName returns costume name', t => { + util.target.currentCostume = 0; // This is 0-indexed. + const name = blocks.getCostumeNumberName({}, util); + t.strictEqual(name, 'first name'); t.end(); }); From 24c6338302cd89583a9cd02f147b0033eb1972f3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 12 Jun 2018 19:27:35 -0300 Subject: [PATCH 3/4] Map costumeName -> costumenumbername [name] ...instead of mapping to a new obsolete/hidden block 'costumename'. Thanks to @kchadha for helping with this! --- src/serialization/sb2.js | 6 ++++++ src/serialization/sb2_specmap.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index 5efd5c9da..9ca378d90 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -954,6 +954,12 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension value: 'number' }; break; + case 'costumeName': + activeBlock.fields.NUMBER_NAME = { + name: 'NUMBER_NAME', + value: 'name' + }; + break; } // Special cases to generate mutations. diff --git a/src/serialization/sb2_specmap.js b/src/serialization/sb2_specmap.js index 44dc41bdd..5079c206f 100644 --- a/src/serialization/sb2_specmap.js +++ b/src/serialization/sb2_specmap.js @@ -429,7 +429,7 @@ const specMap = { ] }, 'costumeName': { - opcode: 'looks_costumename', + opcode: 'looks_costumenumbername', argMap: [ ] }, From c24e34d4e3bb5970f213a17bc70bf1c5b46f9924 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 12 Jun 2018 19:31:53 -0300 Subject: [PATCH 4/4] Remove unused getCostumeName function --- src/blocks/scratch3_looks.js | 6 ------ test/unit/blocks_looks.js | 7 ------- 2 files changed, 13 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 487e61389..4a7994a4a 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -252,7 +252,6 @@ class Scratch3LooksBlocks { looks_goforwardbackwardlayers: this.goForwardBackwardLayers, looks_size: this.getSize, looks_costumenumbername: this.getCostumeNumberName, - looks_costumename: this.getCostumeName, looks_backdropnumbername: this.getBackdropNumberName }; } @@ -489,11 +488,6 @@ class Scratch3LooksBlocks { // Else return name return util.target.getCostumes()[util.target.currentCostume].name; } - - getCostumeName (args, util) { - // Obsolete block from earlier Scratch versions. - return util.target.getCostumes()[util.target.currentCostume].name; - } } module.exports = Scratch3LooksBlocks; diff --git a/test/unit/blocks_looks.js b/test/unit/blocks_looks.js index e5d0ab2ff..a9602a706 100644 --- a/test/unit/blocks_looks.js +++ b/test/unit/blocks_looks.js @@ -39,13 +39,6 @@ test('getCostumeNumberName can return costume name', t => { t.end(); }); -test('getCostumeName returns costume name', t => { - util.target.currentCostume = 0; // This is 0-indexed. - const name = blocks.getCostumeNumberName({}, util); - t.strictEqual(name, 'first name'); - t.end(); -}); - test('getBackdropNumberName returns 1-indexed costume number', t => { util.target.currentCostume = 2; // This is 0-indexed. const args = {NUMBER_NAME: 'number'};