Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branchIconURI #174

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.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: './static/blocks-media/repeat.svg', // TODO: use a constant or make this configurable?
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
Expand Down
39 changes: 39 additions & 0 deletions test/unit/tw_branch_icon_uri.js
Original file line number Diff line number Diff line change
@@ -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();
});
Loading