From 5d6669db6d849af5318459f5e3e2c7fee9260f38 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Mon, 22 Apr 2019 17:47:53 -0700 Subject: [PATCH] add "scratch_extension" only if a block has an icon --- src/containers/blocks.jsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx index e36998b85..12fa31b7d 100644 --- a/src/containers/blocks.jsx +++ b/src/containers/blocks.jsx @@ -51,7 +51,7 @@ const DroppableBlocks = DropAreaHOC([ // TODO: grow this until it can fully replace `_convertForScratchBlocks` in the VM runtime // :( where should this live? -const defineDynamicBlock = (ScratchBlocks, categoryInfo, extendedOpcode) => ({ +const defineDynamicBlock = (ScratchBlocks, categoryInfo, staticBlockInfo, extendedOpcode) => ({ init: function () { const blockJson = { type: extendedOpcode, @@ -59,9 +59,15 @@ const defineDynamicBlock = (ScratchBlocks, categoryInfo, extendedOpcode) => ({ category: categoryInfo.name, colour: categoryInfo.color1, colourSecondary: categoryInfo.color2, - colourTertiary: categoryInfo.color3, - extensions: ['scratch_extension'] + colourTertiary: categoryInfo.color3 }; + // There is a scratch-blocks / Blockly extension called "scratch_extension" which adjusts the styling of + // blocks to allow for an icon, a feature of Scratch extension blocks. However, Scratch "core" extension + // blocks don't have icons and so they should not use 'scratch_extension'. Adding a scratch-blocks / Blockly + // extension after `jsonInit` isn't fully supported (?), so we decide now whether there will be an icon. + if (staticBlockInfo.blockIconURI || categoryInfo.blockIconURI) { + blockJson.extensions = ['scratch_extension']; + } this.jsonInit(blockJson); this.blockInfoText = '{}'; this.needsBlockInfoUpdate = true; @@ -495,7 +501,8 @@ class Blocks extends React.Component { // The factory should only know static info about the block: the category info and the opcode. // Anything else will be picked up from the XML attached to the block instance. const extendedOpcode = `${categoryInfo.id}_${blockInfo.info.opcode}`; - const blockDefinition = defineDynamicBlock(this.ScratchBlocks, categoryInfo, extendedOpcode); + const blockDefinition = + defineDynamicBlock(this.ScratchBlocks, categoryInfo, blockInfo, extendedOpcode); this.ScratchBlocks.Blocks[extendedOpcode] = blockDefinition; }); }