Guest User

Untitled

a guest
Mar 25th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   plus: function() {
  2.     this.addPart_();
  3.     this.updateMinus_();
  4.   },
  5.   minus: function() {
  6.     if (this.elseIfCount_ == 0) {  // Handles programmatic calling (just in case).
  7.       return;
  8.     }
  9.     this.removePart_();
  10.     this.updateMinus_();
  11.   },
  12.   // To properly keep track of indices we have to increment before/after adding
  13.   // the inputs, and decrement the opposite.
  14.   // Because we want our first elseif to be IF1 (not IF0) we increment first.
  15.   addPart_: function() {
  16.     this.elseIfCount_++;
  17.     this.appendValueInput('IF' + this.elseIfCount_)
  18.         .setCheck('Boolean')
  19.         .appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF']);
  20.     this.appendStatementInput('DO' + this.elseIfCount_)
  21.         .appendField(Blockly.Msg['CONTROLS_IF_MSG_THEN']);
  22.  
  23.     // Handle if-elseif-else block.
  24.     if (this.getInput('ELSE')) {
  25.       this.moveInputBefore('ELSE', /* put at end */ null);
  26.     }
  27.   },
  28.   removePart_: function() {
  29.     this.removeInput('IF' + this.elseIfCount_);
  30.     this.removeInput('DO' + this.elseIfCount_);
  31.     this.elseIfCount_--;
  32.   },
  33.   updateMinus_: function() {
  34.     var minusField = this.getField('MINUS');
  35.     if (!minusField) {  // Assume we want to add one.
  36.       this.topInput_.insertFieldAt(1, new FieldMinus(), 'MINUS');
  37.     } else if (!this.elseIfCount_) {
  38.       this.topInput_.removeField('MINUS');
  39.     }
  40.   }
  41.  
  42.  
  43. // Mutator helper function to add the plus.
  44. const controlsIfHelper = function() {
  45.   this.topInput_ = this.getInput('IF0');
  46.   this.topInput_.insertFieldAt(0, new FieldPlus(), 'PLUS');
  47. };
Add Comment
Please, Sign In to add comment