switch n break
This commit is contained in:
parent
959c9034b8
commit
818924b210
2 changed files with 95 additions and 1 deletions
|
|
@ -2,11 +2,16 @@
|
|||
<category name="Control" colour="#FFAB19">
|
||||
<block type="control_ifthen" />
|
||||
<block type="control_ifthenelse" />
|
||||
<sep gap="48"></sep>
|
||||
<block type="control_switch" />
|
||||
<block type="control_case" />
|
||||
<block type="control_default" />
|
||||
<block type="control_break" />
|
||||
</category>
|
||||
<category name="Literals" colour="#59C08E">
|
||||
<block type="literals_true" />
|
||||
<block type="literals_false" />
|
||||
<sep gap="64"></sep>
|
||||
<sep gap="48"></sep>
|
||||
<block type="literals_number" />
|
||||
<block type="literals_string" />
|
||||
</category>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue