Skip to content

Commit

Permalink
Add custom hats to procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings authored Mar 5, 2024
1 parent b1301f8 commit 656b6d6
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions blocks_vertical/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Blockly.ScratchBlocks.ProcedureUtils.callerMutationToDom = function() {
container.setAttribute('proccode', this.procCode_);
container.setAttribute('argumentids', JSON.stringify(this.argumentIds_));
container.setAttribute('warp', JSON.stringify(this.warp_));
container.setAttribute('hat', this.hat_);
container.setAttribute('colour', this.colour_);
if (this.return_ !== Blockly.PROCEDURES_CALL_TYPE_STATEMENT) {
container.setAttribute('return', this.return_);
Expand Down Expand Up @@ -84,6 +85,8 @@ Blockly.ScratchBlocks.ProcedureUtils.callerDomToMutation = function(xmlElement)
if (this.return_ !== Blockly.PROCEDURES_CALL_TYPE_STATEMENT) {
this.workspace.enableProcedureReturns();
}

this.hat_ = xmlElement.getAttribute('hat');
this.updateDisplay_();
};

Expand Down Expand Up @@ -132,6 +135,7 @@ Blockly.ScratchBlocks.ProcedureUtils.definitionDomToMutation = function(xmlEleme
this.displayNames_ = JSON.parse(xmlElement.getAttribute('argumentnames'));
this.argumentDefaults_ = JSON.parse(
xmlElement.getAttribute('argumentdefaults'));

this.updateDisplay_();
if (this.updateArgumentReporterNames_) {
this.updateArgumentReporterNames_(prevArgIds, prevDisplayNames);
Expand Down Expand Up @@ -169,7 +173,10 @@ Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_ = function() {
this.deleteShadows_(connectionMap);

this.setColour(this.colour_);
if (!wasRendered && this.getReturn) {
if (!wasRendered && this.hat_) {
this.setPreviousStatement(false);
this.setNextStatement(true);
} else if (!wasRendered && this.getReturn) {
this.setInputsInline(true);
if (this.getReturn() === Blockly.PROCEDURES_CALL_TYPE_STATEMENT) {
this.setPreviousStatement(true, null);
Expand Down Expand Up @@ -735,12 +742,12 @@ Blockly.ScratchBlocks.ProcedureUtils.getWarp = function() {
};

/**
* Externally-visible function to set the warp on procedure declaration.
* @param {boolean} warp The value of the warp_ property.
* Externally-visible function to get the warp on procedure declaration.
* @return {boolean} The value of the warp_ property.
* @public
*/
Blockly.ScratchBlocks.ProcedureUtils.setWarp = function(warp) {
this.warp_ = warp;
Blockly.ScratchBlocks.ProcedureUtils.getHat = function() {
return this.hat_;
};

/**
Expand All @@ -751,6 +758,25 @@ Blockly.ScratchBlocks.ProcedureUtils.getReturn = function() {
return this.return_;
};

/**
* Externally-visible function to set the warp on procedure declaration.
* @param {boolean} warp The value of the warp_ property.
* @public
*/
Blockly.ScratchBlocks.ProcedureUtils.setWarp = function(warp) {
this.warp_ = warp;
};

/**
* Externally-visible function to set the warp on procedure declaration.
* @param {boolean} warp The value of the warp_ property.

Check failure on line 772 in blocks_vertical/procedures.js

View workflow job for this annotation

GitHub Actions / build

Expected JSDoc for 'hat' but found 'warp'
* @public
*/
Blockly.ScratchBlocks.ProcedureUtils.setHat = function(hat) {
this.hat_ = hat;
this.setPreviousStatement(!hat);
};

/**
* Callback to remove a field, only for the declaration block.
* @param {Blockly.Field} field The field being removed.
Expand Down Expand Up @@ -885,6 +911,7 @@ Blockly.Blocks['procedures_call'] = {
this.argumentIds_ = [];
this.warp_ = false;
this.return_ = Blockly.PROCEDURES_CALL_TYPE_STATEMENT;
this.hat_ = false;
},
// Shared.
getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,
Expand Down Expand Up @@ -981,6 +1008,8 @@ Blockly.Blocks['procedures_declaration'] = {
focusLastEditor_: Blockly.ScratchBlocks.ProcedureUtils.focusLastEditor_,
getWarp: Blockly.ScratchBlocks.ProcedureUtils.getWarp,
setWarp: Blockly.ScratchBlocks.ProcedureUtils.setWarp,
getHat: Blockly.ScratchBlocks.ProcedureUtils.getHat,
setHat: Blockly.ScratchBlocks.ProcedureUtils.setHat,
addLabelExternal: Blockly.ScratchBlocks.ProcedureUtils.addLabelExternal,
addBooleanExternal: Blockly.ScratchBlocks.ProcedureUtils.addBooleanExternal,
addStringExternal: Blockly.ScratchBlocks.ProcedureUtils.addStringExternal,
Expand Down

0 comments on commit 656b6d6

Please sign in to comment.