From 69294d83445a5d4e428bbc6ac257011179c31e1e Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 28 Jan 2015 17:45:13 -0800 Subject: [PATCH] Change logic compare block to eject mismatched blocks. --- blocks/logic.js | 21 ++++++++++++--------- blocks_compressed.js | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/blocks/logic.js b/blocks/logic.js index fbb68ab665d..4ae0f80c05a 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -312,15 +312,18 @@ Blockly.Blocks['logic_compare'] = { } var blockA = this.getInputTargetBlock('A'); var blockB = this.getInputTargetBlock('B'); - if (blockA) { - this.getInput('B').setCheck(blockA.outputConnection.check_); - } - if (blockB) { - this.getInput('A').setCheck(blockB.outputConnection.check_); - } - if (!blockA && !blockB) { - this.getInput('A').setCheck(null); - this.getInput('B').setCheck(null); + // Keep track of which block was added second + // (so the first block may be ejected upon mismatch). + if (blockA && !blockB) { + this.blockAPriority_ = false; + } else if (!blockA && blockB) { + this.blockAPriority_ = true; + } else if (blockA && blockB && + !blockA.outputConnection.checkType_(blockB.outputConnection)) { + // Mismatch between two inputs. Disconnect one and bump it away. + var child = this.blockAPriority_ ? blockB : blockA; + child.setParent(null); + child.bumpNeighbours_(); } } }; diff --git a/blocks_compressed.js b/blocks_compressed.js index 19d7edec5c0..0e42fe73321 100644 --- a/blocks_compressed.js +++ b/blocks_compressed.js @@ -47,8 +47,8 @@ b++;break;case "controls_if_else":d=this.getInput("ELSE");a.statementConnection_ Blockly.Blocks.controls_if_elseif={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSEIF_TITLE_ELSEIF);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP);this.contextMenu=!1}}; Blockly.Blocks.controls_if_else={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE);this.setPreviousStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP);this.contextMenu=!1}}; Blockly.Blocks.logic_compare={init:function(){var a=Blockly.RTL?[["=","EQ"],["\u2260","NEQ"],[">","LT"],["\u2265","LTE"],["<","GT"],["\u2264","GTE"]]:[["=","EQ"],["\u2260","NEQ"],["<","LT"],["\u2264","LTE"],[">","GT"],["\u2265","GTE"]];this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendValueInput("A");this.appendValueInput("B").appendField(new Blockly.FieldDropdown(a),"OP");this.setInputsInline(!0);var b=this;this.setTooltip(function(){var a= -b.getFieldValue("OP");return{EQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,NEQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,LT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,LTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,GT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,GTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE}[a]})},onchange:function(){if(this.workspace){var a=this.getInputTargetBlock("A"),b=this.getInputTargetBlock("B");a&&this.getInput("B").setCheck(a.outputConnection.check_);b&&this.getInput("A").setCheck(b.outputConnection.check_); -a||b||(this.getInput("A").setCheck(null),this.getInput("B").setCheck(null))}}}; +b.getFieldValue("OP");return{EQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,NEQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,LT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,LTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,GT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,GTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE}[a]})},onchange:function(){if(this.workspace){var a=this.getInputTargetBlock("A"),b=this.getInputTargetBlock("B");a&&!b?this.blockAPriority_=!1:!a&&b?this.blockAPriority_=!0:a&&b&&!a.outputConnection.checkType_(b.outputConnection)&& +(a=this.blockAPriority_?b:a,a.setParent(null),a.bumpNeighbours_())}}}; Blockly.Blocks.logic_operation={init:function(){var a=[[Blockly.Msg.LOGIC_OPERATION_AND,"AND"],[Blockly.Msg.LOGIC_OPERATION_OR,"OR"]];this.setHelpUrl(Blockly.Msg.LOGIC_OPERATION_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendValueInput("A").setCheck("Boolean");this.appendValueInput("B").setCheck("Boolean").appendField(new Blockly.FieldDropdown(a),"OP");this.setInputsInline(!0);var b=this;this.setTooltip(function(){var a=b.getFieldValue("OP");return{AND:Blockly.Msg.LOGIC_OPERATION_TOOLTIP_AND, OR:Blockly.Msg.LOGIC_OPERATION_TOOLTIP_OR}[a]})}};Blockly.Blocks.logic_negate={init:function(){this.setHelpUrl(Blockly.Msg.LOGIC_NEGATE_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.interpolateMsg(Blockly.Msg.LOGIC_NEGATE_TITLE,["BOOL","Boolean",Blockly.ALIGN_RIGHT],Blockly.ALIGN_RIGHT);this.setTooltip(Blockly.Msg.LOGIC_NEGATE_TOOLTIP)}}; Blockly.Blocks.logic_boolean={init:function(){var a=[[Blockly.Msg.LOGIC_BOOLEAN_TRUE,"TRUE"],[Blockly.Msg.LOGIC_BOOLEAN_FALSE,"FALSE"]];this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendDummyInput().appendField(new Blockly.FieldDropdown(a),"BOOL");this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP)}};