Skip to content

Commit bd0cf91

Browse files
Add branchIconURI (#174)
Co-authored-by: Muffin <[email protected]>
1 parent 24b6036 commit bd0cf91

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/engine/runtime.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1408,13 +1408,13 @@ class Runtime extends EventEmitter {
14081408
if (!blockInfo.disableMonitor && context.inputList.length === 0) {
14091409
blockJSON.checkboxInFlyout = true;
14101410
}
1411-
} else if (blockInfo.blockType === BlockType.LOOP) {
1411+
} else if (blockInfo.blockType === BlockType.LOOP || blockInfo.branchIconURI) {
14121412
// Add icon to the bottom right of a loop block
14131413
blockJSON[`lastDummyAlign${outLineNum}`] = 'RIGHT';
14141414
blockJSON[`message${outLineNum}`] = '%1';
14151415
blockJSON[`args${outLineNum}`] = [{
14161416
type: 'field_image',
1417-
src: './static/blocks-media/repeat.svg', // TODO: use a constant or make this configurable?
1417+
src: blockInfo.branchIconURI || './static/blocks-media/repeat.svg',
14181418
width: 24,
14191419
height: 24,
14201420
alt: '*', // TODO remove this since we don't use collapsed blocks in scratch

test/unit/tw_branch_icon_uri.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const {test} = require('tap');
2+
const VirtualMachine = require('../../src/virtual-machine');
3+
const BlockType = require('../../src/extension-support/block-type');
4+
5+
test('branchIconURI', t => {
6+
const vm = new VirtualMachine();
7+
vm.extensionManager._registerInternalExtension({
8+
getInfo: () => ({
9+
id: 'testextension',
10+
name: 'test',
11+
blocks: [
12+
{
13+
blockType: BlockType.LOOP,
14+
opcode: 'block1',
15+
text: 'no custom icon'
16+
},
17+
{
18+
blockType: BlockType.LOOP,
19+
opcode: 'block2',
20+
text: 'LOOP with custom icon',
21+
branchIconURI: 'data:whatever1'
22+
},
23+
{
24+
blockType: BlockType.CONDITIONAL,
25+
opcode: 'block2',
26+
text: 'CONDITIONAL with custom icon',
27+
branchIconURI: 'data:whatever2'
28+
}
29+
]
30+
})
31+
});
32+
33+
const blocks = vm.runtime.getBlocksJSON();
34+
t.equal(blocks[0].args2[0].src, './static/blocks-media/repeat.svg', 'default custom icon');
35+
t.equal(blocks[1].args2[0].src, 'data:whatever1', 'LOOP with custom icon');
36+
t.equal(blocks[2].args2[0].src, 'data:whatever2', 'CONDITIONAL with custom icon');
37+
38+
t.end();
39+
});

0 commit comments

Comments
 (0)