From 55600f4e2a06c63d3c70c553a492db78229e8786 Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:11:31 -0400 Subject: [PATCH 1/9] Create block-shape.js --- src/extension-support/block-shape.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/extension-support/block-shape.js diff --git a/src/extension-support/block-shape.js b/src/extension-support/block-shape.js new file mode 100644 index 00000000000..9c827ef1a9f --- /dev/null +++ b/src/extension-support/block-shape.js @@ -0,0 +1,22 @@ +/** + * Types of block shapes + * @enum {number} + */ +const BlockShape = { + /** + * Output shape: hexagonal (booleans/predicates). + */ + HEXAGONAL: 1, + + /** + * Output shape: rounded (numbers). + */ + ROUND: 2, + + /** + * Output shape: squared (any/all values; strings). + */ + SQUARE: 3, +}; + +module.exports = BlockShape; From 216bf0babc6040138e883ae829fc81bd20c7638e Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:15:28 -0400 Subject: [PATCH 2/9] Update runtime.js --- src/engine/runtime.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index f407dbdd5c8..455b3e96051 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1429,6 +1429,12 @@ class Runtime extends EventEmitter { break; } + // Check if "blockShape" is specified + if (blockInfo.blockShape) { + blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; + } + + const blockText = Array.isArray(blockInfo.text) ? blockInfo.text : [blockInfo.text]; let inTextNum = 0; // text for the next block "arm" is blockText[inTextNum] let inBranchNum = 0; // how many branches have we placed into the JSON so far? From 36cafd09a68b356c7353840db5a5060e33fa1ec8 Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:17:54 -0400 Subject: [PATCH 3/9] use ScratchBlocksConstants instead of manual definitions --- src/extension-support/block-shape.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/extension-support/block-shape.js b/src/extension-support/block-shape.js index 9c827ef1a9f..190324b71e2 100644 --- a/src/extension-support/block-shape.js +++ b/src/extension-support/block-shape.js @@ -1,3 +1,6 @@ +// Use the constants instead of manually redefining them again +const ScratchBlocksConstants = require('./scratch-blocks-constants'); + /** * Types of block shapes * @enum {number} @@ -6,17 +9,17 @@ const BlockShape = { /** * Output shape: hexagonal (booleans/predicates). */ - HEXAGONAL: 1, + HEXAGONAL: ScratchBlocksConstants.OUTPUT_SHAPE_HEXAGONAL, /** * Output shape: rounded (numbers). */ - ROUND: 2, + ROUND: ScratchBlocksConstants.OUTPUT_SHAPE_ROUND, /** * Output shape: squared (any/all values; strings). */ - SQUARE: 3, + SQUARE: ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE, }; module.exports = BlockShape; From 1c24063e530b20abaf04d34fbfb553986c0a9d6d Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:24:07 -0400 Subject: [PATCH 4/9] add default comment --- src/engine/runtime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 455b3e96051..db9ab7caf5d 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1431,7 +1431,7 @@ class Runtime extends EventEmitter { // Check if "blockShape" is specified if (blockInfo.blockShape) { - blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; + blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; // Default to the round/reporter shape } From 5ae68241c4fab185ae7a77865e0dda153910dbb4 Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:24:29 -0400 Subject: [PATCH 5/9] fix trailing comma (eslint) --- src/extension-support/block-shape.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension-support/block-shape.js b/src/extension-support/block-shape.js index 190324b71e2..f4f37de16d3 100644 --- a/src/extension-support/block-shape.js +++ b/src/extension-support/block-shape.js @@ -19,7 +19,7 @@ const BlockShape = { /** * Output shape: squared (any/all values; strings). */ - SQUARE: ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE, + SQUARE: ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE }; module.exports = BlockShape; From 3868c3d99e2b4dd51ca842a6f587450f2d069dba Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:28:36 -0400 Subject: [PATCH 6/9] revert "add default comment" --- src/engine/runtime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index db9ab7caf5d..455b3e96051 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1431,7 +1431,7 @@ class Runtime extends EventEmitter { // Check if "blockShape" is specified if (blockInfo.blockShape) { - blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; // Default to the round/reporter shape + blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; } From ed18846c3b30739252aaf5195fc64a55a272d40b Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:33:27 -0400 Subject: [PATCH 7/9] expose BlockShape to the common api --- src/extension-support/tw-extension-api-common.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extension-support/tw-extension-api-common.js b/src/extension-support/tw-extension-api-common.js index e2ac0b74d0f..20503d56dcf 100644 --- a/src/extension-support/tw-extension-api-common.js +++ b/src/extension-support/tw-extension-api-common.js @@ -1,11 +1,13 @@ const ArgumentType = require('./argument-type'); const BlockType = require('./block-type'); +const BlockShape = require('./block-shape'); const TargetType = require('./target-type'); const Cast = require('../util/cast'); const Scratch = { ArgumentType, BlockType, + BlockShape, TargetType, Cast }; From f3186c83cef2870a61de3d09dcd4530568f6edab Mon Sep 17 00:00:00 2001 From: AshimeeAlt <161080149+AshimeeAlt@users.noreply.github.com> Date: Sun, 26 May 2024 12:35:50 -0400 Subject: [PATCH 8/9] scratch-blocks-constants.js is in src/engine not src/extension-support :facepalm: --- src/extension-support/block-shape.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension-support/block-shape.js b/src/extension-support/block-shape.js index f4f37de16d3..854975ada88 100644 --- a/src/extension-support/block-shape.js +++ b/src/extension-support/block-shape.js @@ -1,5 +1,5 @@ // Use the constants instead of manually redefining them again -const ScratchBlocksConstants = require('./scratch-blocks-constants'); +const ScratchBlocksConstants = require('../engine/scratch-blocks-constants'); /** * Types of block shapes From 30f09addb8bb198dec0566b2a5b83b9ed37cae7e Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Tue, 20 May 2025 21:44:28 -0500 Subject: [PATCH 9/9] cleanup, add test cases --- src/engine/runtime.js | 5 +-- .../{block-shape.js => tw-block-shape.js} | 0 .../tw-extension-api-common.js | 2 +- test/unit/tw_block_shape.js | 38 +++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) rename src/extension-support/{block-shape.js => tw-block-shape.js} (100%) create mode 100644 test/unit/tw_block_shape.js diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 455b3e96051..503a1fbc449 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1429,12 +1429,11 @@ class Runtime extends EventEmitter { break; } - // Check if "blockShape" is specified + // Allow extensiosn to override outputShape if (blockInfo.blockShape) { - blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; + blockJSON.outputShape = blockInfo.blockShape; } - const blockText = Array.isArray(blockInfo.text) ? blockInfo.text : [blockInfo.text]; let inTextNum = 0; // text for the next block "arm" is blockText[inTextNum] let inBranchNum = 0; // how many branches have we placed into the JSON so far? diff --git a/src/extension-support/block-shape.js b/src/extension-support/tw-block-shape.js similarity index 100% rename from src/extension-support/block-shape.js rename to src/extension-support/tw-block-shape.js diff --git a/src/extension-support/tw-extension-api-common.js b/src/extension-support/tw-extension-api-common.js index 20503d56dcf..1f5928fbc0f 100644 --- a/src/extension-support/tw-extension-api-common.js +++ b/src/extension-support/tw-extension-api-common.js @@ -1,6 +1,6 @@ const ArgumentType = require('./argument-type'); const BlockType = require('./block-type'); -const BlockShape = require('./block-shape'); +const BlockShape = require('./tw-block-shape'); const TargetType = require('./target-type'); const Cast = require('../util/cast'); diff --git a/test/unit/tw_block_shape.js b/test/unit/tw_block_shape.js new file mode 100644 index 00000000000..a5ef50282a6 --- /dev/null +++ b/test/unit/tw_block_shape.js @@ -0,0 +1,38 @@ +const {test} = require('tap'); +const Runtime = require('../../src/engine/runtime'); +const Scratch = require('../../src/extension-support/tw-extension-api-common'); + +test('blockShape', t => { + const rt = new Runtime(); + rt._registerExtensionPrimitives({ + id: 'shapetest', + name: 'shapetest', + blocks: [ + { + blockType: Scratch.BlockType.REPORTER, + blockShape: Scratch.BlockShape.HEXAGONAL, + opcode: 'hexagonal', + text: 'hexagonal' + }, + { + blockType: Scratch.BlockType.BOOLEAN, + blockShape: Scratch.BlockShape.ROUND, + opcode: 'round', + text: 'round' + }, + { + blockType: Scratch.BlockType.REPORTER, + blockShape: Scratch.BlockShape.SQUARE, + opcode: 'square', + text: 'square' + } + ] + }); + + const json = rt.getBlocksJSON(); + t.equal(json.length, 3); + t.equal(json[0].outputShape, 1); + t.equal(json[1].outputShape, 2); + t.equal(json[2].outputShape, 3); + t.end(); +});