Skip to content

Commit 40540a9

Browse files
committed
fixed weird missing visual edits on define blocks
1 parent 75f0b6f commit 40540a9

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

blocks_vertical/procedures.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ Blockly.ScratchBlocks.ProcedureUtils.definitionDomToMutation = function(xmlEleme
117117
this.argumentDefaults_ = JSON.parse(xmlElement.getAttribute('argumentdefaults'));
118118
this.output_ = JSON.parse(xmlElement.getAttribute('returns'));
119119
this.outputType = JSON.parse(xmlElement.getAttribute('optype'));
120-
this.updateDisplay_();
121120
this.edited = JSON.parse(xmlElement.getAttribute('edited'));
122121
this.image = xmlElement.innerText;
123122
this.color = JSON.parse(xmlElement.getAttribute('color'));
124123
this.image = xmlElement.innerText;
124+
this.updateDisplay_();
125125
if (this.updateArgumentReporterNames_) {
126126
this.updateArgumentReporterNames_(prevArgIds, prevDisplayNames);
127127
}
@@ -159,7 +159,16 @@ Blockly.ScratchBlocks.ProcedureUtils.updateDisplay_ = function() {
159159
this.createAllInputs_(connectionMap);
160160
this.deleteShadows_(connectionMap);
161161
this.setOutputShape(Blockly.OUTPUT_SHAPE_SQUARE);
162-
if (this.color) this.setColour(this.color.primary, this.color.secondary, this.color.tertiary)
162+
if (!this.color) this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
163+
this.setColour(...this.color)
164+
if (
165+
this.outputConnection &&
166+
this.outputConnection.targetConnection &&
167+
this.outputConnection.targetConnection.parentBlock_ &&
168+
(this.outputConnection.targetConnection.parentBlock_.type === 'procedures_definition' ||
169+
this.outputConnection.targetConnection.parentBlock_.type === 'procedures_definition_return')) {
170+
this.outputConnection.targetConnection.parentBlock_.setColour(...this.color)
171+
}
163172
if (this.output_) {
164173
this.setPreviousStatement(false)
165174
this.setNextStatement(false)
@@ -755,16 +764,12 @@ Blockly.ScratchBlocks.ProcedureUtils.unsetImage = function() {
755764
}
756765

757766
Blockly.ScratchBlocks.ProcedureUtils.setColor = function(primary, secondary, tertiary) {
758-
this.color = {
759-
primary,
760-
secondary,
761-
tertiary
762-
}
767+
this.color = [primary, secondary, tertiary]
763768
this.updateDisplay_();
764769
}
765770

766771
Blockly.ScratchBlocks.ProcedureUtils.removeColor = function() {
767-
this.color = Blockly.Colours.more
772+
this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
768773
this.updateDisplay_();
769774
}
770775

@@ -935,7 +940,7 @@ Blockly.Blocks['procedures_call'] = {
935940
this.edited = false
936941
this.outputType = 'statement'
937942
this.image = ''
938-
this.color = Blockly.Colours.more
943+
this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
939944
},
940945
// Shared.
941946
getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,
@@ -979,7 +984,7 @@ Blockly.Blocks['procedures_prototype'] = {
979984
this.edited = false
980985
this.outputType = 'statement'
981986
this.image = ''
982-
this.color = Blockly.Colours.more
987+
this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
983988
},
984989
// Shared.
985990
getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,
@@ -1021,7 +1026,7 @@ Blockly.Blocks['procedures_declaration'] = {
10211026
this.edited = false
10221027
this.outputType = 'statement'
10231028
this.image = ''
1024-
this.color = Blockly.Colours.more
1029+
this.color = [Blockly.Colours.more.primary, Blockly.Colours.more.secondary, Blockly.Colours.more.tertiary]
10251030
},
10261031
// Shared.
10271032
getProcCode: Blockly.ScratchBlocks.ProcedureUtils.getProcCode,

tests/custom_procedure_playground.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@
203203
mutationRoot.initSvg();
204204
mutationRoot.render(false);
205205
var color = mutationRoot.color
206-
primary.value = color.primary
207-
secondary.value = color.secondary
208-
tertiary.value = color.tertiary
206+
primary.value = color[0]
207+
secondary.value = color[1]
208+
tertiary.value = color[2]
209209
}
210210

211211
function applyMutation() {

0 commit comments

Comments
 (0)