Merge pull request #145 from TurboWarp/drop-block-anywhere

Add API for extension block to be dropped anywhere
This commit is contained in:
GarboMuffin authored and GitHub committed 2023-07-07 19:38:31 -05:00
commit 7b32cfca8a
2 files changed
+34 -1

No files matched your search

+1 -1
View File
@@ -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:
@@ -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
}
]
});
});