From 1bf394ad83236945a1eb6177f44c261831ef0b5b Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Thu, 29 Jan 2015 11:21:30 +1300 Subject: [PATCH] Update logic block so it is reactive to the input attahced to it. 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. --- blocks/logic.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/blocks/logic.js b/blocks/logic.js index 5bc81db88..b9bc93e9c 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -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.getInputTargetBlock('A') && !me.getInputTargetBlock('B')) { + if (me.getInputTargetBlock('A').outputConnection.check_) { + me.getInput('B').setCheck(me.getInputTargetBlock('A').outputConnection.check_[0]); + } else { + me.getInput('B').setCheck(null); + } + } else if (me.getInputTargetBlock('B') && !me.getInputTargetBlock('A')) { + if (me.getInputTargetBlock('B').outputConnection.check_) { + me.getInputTargetBlock('A').setCheck(me.getInputTargetBlock('B').outputConnection.check_[0]); + } else { + me.getInput('A').setCheck(null); + } + } else if (me.getInputTargetBlock('A') && me.getInputTargetBlock('B')) { + if (me.getInputTargetBlock('A').outputConnection.check_) { + me.getInput('B').setCheck(me.getInputTargetBlock('A').outputConnection.check_[0]); + } else if (me.getInput('B').outputConnection.check_) { + me.getInput('A').setCheck(me.getInputTargetBlock('B').outputConnection.check_[0]); + } + } else { + me.getInput('A').setCheck(null); + me.getInput('B').setCheck(null); + } + } + }); } };