Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- plus: function() {
- this.addPart_();
- this.updateMinus_();
- },
- minus: function() {
- if (this.elseIfCount_ == 0) { // Handles programmatic calling (just in case).
- return;
- }
- this.removePart_();
- this.updateMinus_();
- },
- // To properly keep track of indices we have to increment before/after adding
- // the inputs, and decrement the opposite.
- // Because we want our first elseif to be IF1 (not IF0) we increment first.
- addPart_: function() {
- this.elseIfCount_++;
- this.appendValueInput('IF' + this.elseIfCount_)
- .setCheck('Boolean')
- .appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF']);
- this.appendStatementInput('DO' + this.elseIfCount_)
- .appendField(Blockly.Msg['CONTROLS_IF_MSG_THEN']);
- // Handle if-elseif-else block.
- if (this.getInput('ELSE')) {
- this.moveInputBefore('ELSE', /* put at end */ null);
- }
- },
- removePart_: function() {
- this.removeInput('IF' + this.elseIfCount_);
- this.removeInput('DO' + this.elseIfCount_);
- this.elseIfCount_--;
- },
- updateMinus_: function() {
- var minusField = this.getField('MINUS');
- if (!minusField) { // Assume we want to add one.
- this.topInput_.insertFieldAt(1, new FieldMinus(), 'MINUS');
- } else if (!this.elseIfCount_) {
- this.topInput_.removeField('MINUS');
- }
- }
- // Mutator helper function to add the plus.
- const controlsIfHelper = function() {
- this.topInput_ = this.getInput('IF0');
- this.topInput_.insertFieldAt(0, new FieldPlus(), 'PLUS');
- };
Add Comment
Please, Sign In to add comment