Skip to content

Commit

Permalink
Update logic block so it is reactive to the input attahced to it.
Browse files Browse the repository at this point in the history
i.e. if you place a number in an input the other input changes it's type to number as well.
When you remove all inputs it reverts back to allowing any input type.
  • Loading branch information
pkendall64 committed Jan 28, 2015
1 parent 906b62f commit 8a72a91
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,36 @@ Blockly.Blocks['logic_compare'] = {
};
return TOOLTIPS[op];
});
var myid = this.id;
var bindid = Blockly.addChangeListener(function() {
var me = Blockly.mainWorkspace.getBlockById(myid);
if(null == me) {
Blockly.removeChangeListener(bindid);
} else {
if (me.getInput('A').connection.targetConnection && !me.getInput('B').connection.targetConnection) {
if (me.getInput('A').connection.targetConnection.sourceBlock_.outputConnection.check_) {
me.getInput('B').setCheck(me.getInput('A').connection.targetConnection.sourceBlock_.outputConnection.check_[0]);
} else {
me.getInput('B').setCheck(null);
}
} else if (me.getInput('B').connection.targetConnection && !me.getInput('A').connection.targetConnection) {
if (me.getInput('B').connection.targetConnection.sourceBlock_.outputConnection.check_) {
me.getInput('A').setCheck(me.getInput('B').connection.targetConnection.sourceBlock_.outputConnection.check_[0]);
} else {
me.getInput('A').setCheck(null);
}
} else if (me.getInput('A').connection.targetConnection && me.getInput('B').connection.targetConnection) {
if (me.getInput('A').connection.targetConnection.sourceBlock_.outputConnection.check_) {
me.getInput('B').setCheck(me.getInput('A').connection.targetConnection.sourceBlock_.outputConnection.check_[0]);
} else if (me.getInput('B').connection.targetConnection.sourceBlock_.outputConnection.check_) {
me.getInput('A').setCheck(me.getInput('B').connection.targetConnection.sourceBlock_.outputConnection.check_[0]);
}
} else {
me.getInput('A').setCheck(null);
me.getInput('B').setCheck(null);
}
}
});
}
};

Expand Down

0 comments on commit 8a72a91

Please sign in to comment.