diff --git a/src/lib/Toolbox/Toolbox.xml b/src/lib/Toolbox/Toolbox.xml index ba1c216..e458d2f 100644 --- a/src/lib/Toolbox/Toolbox.xml +++ b/src/lib/Toolbox/Toolbox.xml @@ -2,11 +2,16 @@ + + + + + - + diff --git a/src/resources/blocks/control.js b/src/resources/blocks/control.js index ac83345..8502f9f 100644 --- a/src/resources/blocks/control.js +++ b/src/resources/blocks/control.js @@ -32,6 +32,7 @@ function register() { const code = `if (${CONDITION ? `Boolean(${CONDITION})` : 'false'}) { ${BLOCKS} };`; return `${code}\n`; }) + // if <> then {} else {} registerBlock(`${categoryPrefix}ifthenelse`, { message0: 'if %1 then %2 %3 else %4 %5', @@ -71,6 +72,94 @@ function register() { };`; return `${code}\n`; }) + + // switch statement + registerBlock(`${categoryPrefix}switch`, { + message0: 'switch %1 %2 %3', + args0: [ + { + "type": "input_value", + "name": "VALUE" + }, + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "BLOCKS", + "check": "Case" + } + ], + previousStatement: null, + nextStatement: null, + inputsInline: true, + colour: categoryColor + }, (block) => { + const VALUE = javascriptGenerator.valueToCode(block, 'VALUE', javascriptGenerator.ORDER_ATOMIC); + const BLOCKS = javascriptGenerator.statementToCode(block, 'BLOCKS'); + const code = `switch (${VALUE || "''"}) { ${BLOCKS} };`; + return `${code}\n`; + }) + + // case + registerBlock(`${categoryPrefix}case`, { + message0: 'case %1 %2 %3', + args0: [ + { + "type": "input_value", + "name": "VALUE" + }, + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "BLOCKS" + } + ], + previousStatement: "Case", + nextStatement: "Case", + inputsInline: true, + colour: categoryColor + }, (block) => { + const VALUE = javascriptGenerator.valueToCode(block, 'VALUE', javascriptGenerator.ORDER_ATOMIC); + const BLOCKS = javascriptGenerator.statementToCode(block, 'BLOCKS'); + const code = `case (${VALUE || "''"}): ${BLOCKS}`; + return `${code}\n`; + }) + + // default + registerBlock(`${categoryPrefix}default`, { + message0: 'default %1 %2', + args0: [ + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "BLOCKS" + } + ], + previousStatement: "Case", + inputsInline: true, + colour: categoryColor + }, (block) => { + const BLOCKS = javascriptGenerator.statementToCode(block, 'BLOCKS'); + const code = `default: ${BLOCKS}`; + return `${code}\n`; + }) + + // break + registerBlock(`${categoryPrefix}break`, { + message0: 'break', + args0: [], + previousStatement: null, + inputsInline: true, + colour: categoryColor + }, (block) => { + const code = `break;`; + return `${code}\n`; + }) } export default register;