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:
Andrew n marshall
2016-10-31 11:00:39 -07:00
committed by GitHub
parent 0156f2e103
commit 72ff6d9ead
8 changed files with 115 additions and 63 deletions

View File

@@ -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 = {