From 8f47fc3be716631dd7b73515e6e3b278989cc685 Mon Sep 17 00:00:00 2001 From: Cubester Date: Sun, 17 Dec 2023 18:16:50 -0500 Subject: [PATCH 1/3] Add `branchIcon` --- src/engine/runtime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 1393ee26913..b76bd3863f9 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1408,13 +1408,13 @@ class Runtime extends EventEmitter { if (!blockInfo.disableMonitor && context.inputList.length === 0) { blockJSON.checkboxInFlyout = true; } - } else if (blockInfo.blockType === BlockType.LOOP) { + } else if (blockInfo.blockType === BlockType.LOOP || blockInfo.branchIcon) { // Add icon to the bottom right of a loop block blockJSON[`lastDummyAlign${outLineNum}`] = 'RIGHT'; blockJSON[`message${outLineNum}`] = '%1'; blockJSON[`args${outLineNum}`] = [{ type: 'field_image', - src: './static/blocks-media/repeat.svg', // TODO: use a constant or make this configurable? + src: blockInfo.branchIcon ?? './static/blocks-media/repeat.svg', width: 24, height: 24, alt: '*', // TODO remove this since we don't use collapsed blocks in scratch From ef9466a4fd9d00474b0dd51bd7026055994c9981 Mon Sep 17 00:00:00 2001 From: Muffin Date: Fri, 22 Dec 2023 16:26:16 -0600 Subject: [PATCH 2/3] Rename for consistency and avoid new syntax that our ancient Node.js may not support --- src/engine/runtime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index b76bd3863f9..adfffa78cf4 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1408,13 +1408,13 @@ class Runtime extends EventEmitter { if (!blockInfo.disableMonitor && context.inputList.length === 0) { blockJSON.checkboxInFlyout = true; } - } else if (blockInfo.blockType === BlockType.LOOP || blockInfo.branchIcon) { + } else if (blockInfo.blockType === BlockType.LOOP || blockInfo.branchIconURI) { // Add icon to the bottom right of a loop block blockJSON[`lastDummyAlign${outLineNum}`] = 'RIGHT'; blockJSON[`message${outLineNum}`] = '%1'; blockJSON[`args${outLineNum}`] = [{ type: 'field_image', - src: blockInfo.branchIcon ?? './static/blocks-media/repeat.svg', + src: blockInfo.branchIconURI || './static/blocks-media/repeat.svg', width: 24, height: 24, alt: '*', // TODO remove this since we don't use collapsed blocks in scratch From 8b25fb97ea04a68fa0dde8cfda4e97b04f731633 Mon Sep 17 00:00:00 2001 From: Muffin Date: Fri, 22 Dec 2023 16:43:17 -0600 Subject: [PATCH 3/3] Add test --- test/unit/tw_branch_icon_uri.js | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/unit/tw_branch_icon_uri.js diff --git a/test/unit/tw_branch_icon_uri.js b/test/unit/tw_branch_icon_uri.js new file mode 100644 index 00000000000..2de54dab606 --- /dev/null +++ b/test/unit/tw_branch_icon_uri.js @@ -0,0 +1,39 @@ +const {test} = require('tap'); +const VirtualMachine = require('../../src/virtual-machine'); +const BlockType = require('../../src/extension-support/block-type'); + +test('branchIconURI', t => { + const vm = new VirtualMachine(); + vm.extensionManager._registerInternalExtension({ + getInfo: () => ({ + id: 'testextension', + name: 'test', + blocks: [ + { + blockType: BlockType.LOOP, + opcode: 'block1', + text: 'no custom icon' + }, + { + blockType: BlockType.LOOP, + opcode: 'block2', + text: 'LOOP with custom icon', + branchIconURI: 'data:whatever1' + }, + { + blockType: BlockType.CONDITIONAL, + opcode: 'block2', + text: 'CONDITIONAL with custom icon', + branchIconURI: 'data:whatever2' + } + ] + }) + }); + + const blocks = vm.runtime.getBlocksJSON(); + t.equal(blocks[0].args2[0].src, './static/blocks-media/repeat.svg', 'default custom icon'); + t.equal(blocks[1].args2[0].src, 'data:whatever1', 'LOOP with custom icon'); + t.equal(blocks[2].args2[0].src, 'data:whatever2', 'CONDITIONAL with custom icon'); + + t.end(); +});