mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Adding controls_ifelse block (#722)
Adding controls_ifelse, an if/else block that is loaded from JSON and does not use mutators. This gives "else" capability to Android & iOS implementations, which don't support JavaScript mutators. Added this block to the playground simple toolbox and all generators.
This commit is contained in:
committed by
GitHub
parent
0156f2e103
commit
72ff6d9ead
@@ -32,26 +32,27 @@ goog.require('Blockly.Python');
|
||||
Blockly.Python['controls_if'] = function(block) {
|
||||
// If/elseif/else condition.
|
||||
var n = 0;
|
||||
var argument = Blockly.Python.valueToCode(block, 'IF' + n,
|
||||
Blockly.Python.ORDER_NONE) || 'False';
|
||||
var branch = Blockly.Python.statementToCode(block, 'DO' + n) ||
|
||||
Blockly.Python.PASS;
|
||||
var code = 'if ' + argument + ':\n' + branch;
|
||||
for (n = 1; n <= block.elseifCount_; n++) {
|
||||
argument = Blockly.Python.valueToCode(block, 'IF' + n,
|
||||
Blockly.Python.ORDER_NONE) || 'False';
|
||||
branch = Blockly.Python.statementToCode(block, 'DO' + n) ||
|
||||
var code = '', branchCode, conditionCode;
|
||||
do {
|
||||
conditionCode = Blockly.Python.valueToCode(block, 'IF' + n,
|
||||
Blockly.Python.ORDER_NONE) || 'false';
|
||||
branchCode = Blockly.Python.statementToCode(block, 'DO' + n) ||
|
||||
Blockly.Python.PASS;
|
||||
code += 'elif ' + argument + ':\n' + branch;
|
||||
}
|
||||
if (block.elseCount_) {
|
||||
branch = Blockly.Python.statementToCode(block, 'ELSE') ||
|
||||
code += (n == 0 ? 'if ' : 'elif ' ) + conditionCode + ':\n' + branchCode;
|
||||
|
||||
++n;
|
||||
} while (block.getInput('IF' + n));
|
||||
|
||||
if (block.getInput('ELSE')) {
|
||||
branchCode = Blockly.Python.statementToCode(block, 'ELSE') ||
|
||||
Blockly.Python.PASS;
|
||||
code += 'else:\n' + branch;
|
||||
code += 'else:\n' + branchCode;
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Python['controls_ifelse'] = Blockly.Python['controls_if'];
|
||||
|
||||
Blockly.Python['logic_compare'] = function(block) {
|
||||
// Comparison operator.
|
||||
var OPERATORS = {
|
||||
|
||||
Reference in New Issue
Block a user