Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings committed Sep 28, 2024
1 parent 09103f6 commit a831926
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
37 changes: 29 additions & 8 deletions blocks_vertical/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,4 @@ Blockly.Procedures.getBlockReturnType = function(block) {
} else {
return Blockly.PROCEDURES_CALL_TYPE_STATEMENT;
}
};
};

Check failure on line 730 in core/procedures.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found

Check failure on line 730 in core/procedures.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found

0 comments on commit a831926

Please sign in to comment.