diff --git a/blocks_vertical/procedures.js b/blocks_vertical/procedures.js index 88664b5728..5c90d11c24 100644 --- a/blocks_vertical/procedures.js +++ b/blocks_vertical/procedures.js @@ -172,17 +172,21 @@ Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_ = function() { if (!wasRendered && this.getReturn) { this.setInputsInline(true); - if (this.getReturn() === Blockly.PROCEDURES_CALL_TYPE_STATEMENT) { + + // due to limitations with blockly, all custom reporters with a branch + // must be rendererd with a square output shape. + if (this.hasStatementInput() && this.getReturn() !== Blockly.PROCEDURES_CALL_TYPE_STATEMENT) { + this.setOutput(true, null); + this.setOutputShape(Blockly.OUTPUT_SHAPE_SQUARE); + } else if (this.getReturn() === Blockly.PROCEDURES_CALL_TYPE_STATEMENT) { this.setPreviousStatement(true, null); this.setNextStatement(true, null); + } else if (this.getReturn() === Blockly.PROCEDURES_CALL_TYPE_BOOLEAN) { + this.setOutput(true, null); + this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL); } else { - if (this.getReturn() === Blockly.PROCEDURES_CALL_TYPE_BOOLEAN) { - this.setOutput(true, null); - this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL); - } else { - this.setOutput(true, Blockly.Procedures.ENFORCE_TYPES ? 'Number' : null); - this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); - } + this.setOutput(true, Blockly.Procedures.ENFORCE_TYPES ? 'Number' : null); + this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); } } @@ -193,6 +197,20 @@ Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_ = function() { } }; +/** + * Find if the procedure has a branch input or not. + * @returns {boolean} The type of the return block + */ +Blockly.ScratchBlocks.ProcedureUtils.hasStatementInput = function() { + var inputList = this.inputList; + if (!inputList) return false; + + for (var i = 0; i < inputList.length; i++) { + if (inputList[i].type === 3) return true; + } + return false; +}; + /** * Disconnect old blocks from all value inputs on this block, but hold onto them * in case they can be reattached later. Also save the shadow DOM if it exists. @@ -941,6 +959,7 @@ Blockly.Blocks['procedures_call'] = { deleteShadows_: Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_, createAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_, updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_, + hasStatementInput: Blockly.ScratchBlocks.ProcedureUtils.hasStatementInput, getReturn: Blockly.ScratchBlocks.ProcedureUtils.getReturn, // Exist on all three blocks, but have different implementations. @@ -979,6 +998,7 @@ Blockly.Blocks['procedures_prototype'] = { deleteShadows_: Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_, createAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_, updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_, + hasStatementInput: Blockly.ScratchBlocks.ProcedureUtils.hasStatementInput, // Exist on all three blocks, but have different implementations. mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.definitionMutationToDom, @@ -1014,6 +1034,7 @@ Blockly.Blocks['procedures_declaration'] = { deleteShadows_: Blockly.ScratchBlocks.ProcedureUtils.deleteShadows_, createAllInputs_: Blockly.ScratchBlocks.ProcedureUtils.createAllInputs_, updateDisplay_: Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_, + hasStatementInput: Blockly.ScratchBlocks.ProcedureUtils.hasStatementInput, // Exist on all three blocks, but have different implementations. mutationToDom: Blockly.ScratchBlocks.ProcedureUtils.definitionMutationToDom, diff --git a/core/procedures.js b/core/procedures.js index 2b4c838335..83003b445e 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -727,4 +727,4 @@ Blockly.Procedures.getBlockReturnType = function(block) { } else { return Blockly.PROCEDURES_CALL_TYPE_STATEMENT; } -}; +}; \ No newline at end of file