From 33439939d20393dfa16213426a7a94bc78309f6d Mon Sep 17 00:00:00 2001 From: GarboMuffin Date: Thu, 29 Jun 2023 22:35:34 -0500 Subject: [PATCH] Add API for extension block to be dropped anywhere --- src/engine/runtime.js | 2 +- test/integration/tw_allow_drop_anywhere.js | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/integration/tw_allow_drop_anywhere.js diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 210149e8..eae8b773 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1317,7 +1317,7 @@ class Runtime extends EventEmitter { } break; case BlockType.REPORTER: - blockJSON.output = 'String'; // TODO: distinguish number & string here? + blockJSON.output = blockInfo.allowDropAnywhere ? null : 'String'; // TODO: distinguish number & string here? blockJSON.outputShape = ScratchBlocksConstants.OUTPUT_SHAPE_ROUND; break; case BlockType.BOOLEAN: diff --git a/test/integration/tw_allow_drop_anywhere.js b/test/integration/tw_allow_drop_anywhere.js new file mode 100644 index 00000000..0bc19fbc --- /dev/null +++ b/test/integration/tw_allow_drop_anywhere.js @@ -0,0 +1,33 @@ +const {test} = require('tap'); +const Runtime = require('../../src/engine/runtime'); +const BlockType = require('../../src/extension-support/block-type'); + +test('allowDropAnywhere', t => { + t.plan(2); + + const rt = new Runtime(); + + rt.on('EXTENSION_ADDED', json => { + t.equal(json.blocks[0].json.output, 'String'); + t.equal(json.blocks[1].json.output, null); + t.end(); + }); + + rt._registerExtensionPrimitives({ + id: 'testextension', + name: 'test', + blocks: [ + { + opcode: 'drop1', + text: 'drop not anywhere', + blockType: BlockType.REPORTER + }, + { + opcode: 'drop2', + text: 'drop anywhere', + blockType: BlockType.REPORTER, + allowDropAnywhere: true + } + ] + }); +});