Skip to content

Commit eb518e7

Browse files
author
SebCanet
committed
fix variable regression
1 parent 1b1b4da commit eb518e7

File tree

4 files changed

+130
-126
lines changed

4 files changed

+130
-126
lines changed

www/blocks/BlocklyArduino/variables.js

Lines changed: 124 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -30,148 +30,150 @@ goog.require('Blockly.Blocks');
3030
goog.require('Blockly.Types');
3131

3232
Blockly.Blocks['variables_get'] = {
33-
/**
34-
* Block for variable getter.
35-
* @this Blockly.Block
36-
*/
37-
init: function() {
38-
this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);
39-
this.setColour(Blockly.Blocks.variables.HUE);
40-
this.appendDummyInput()
33+
/**
34+
* Block for variable getter.
35+
* @this Blockly.Block
36+
*/
37+
init: function () {
38+
this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);
39+
this.setColour(Blockly.Blocks.variables.HUE);
40+
this.appendDummyInput()
4141
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR');
42-
this.setOutput(true);
43-
this.setTooltip(Blockly.Msg.VARIABLES_GET_TOOLTIP);
44-
this.contextMenuMsg_ = Blockly.Msg.VARIABLES_GET_CREATE_SET;
45-
},
46-
contextMenuType_: 'variables_set',
47-
/**
48-
* Add menu option to create getter/setter block for this setter/getter.
49-
* @param {!Array} options List of menu options to add to.
50-
* @this Blockly.Block
51-
*/
52-
customContextMenu: function(options) {
53-
var option = {enabled: true};
54-
var name = this.getFieldValue('VAR');
55-
option.text = this.contextMenuMsg_.replace('%1', name);
56-
var xmlField = goog.dom.createDom('field', null, name);
57-
xmlField.setAttribute('name', 'VAR');
58-
var xmlBlock = goog.dom.createDom('block', null, xmlField);
59-
xmlBlock.setAttribute('type', this.contextMenuType_);
60-
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
61-
options.push(option);
62-
},
63-
/**
64-
* @return {!string} Retrieves the type (stored in varType) of this block.
65-
* @this Blockly.Block
66-
*/
67-
getBlockType: function() {
68-
return [Blockly.Types.UNDEF, this.getFieldValue('VAR')];
69-
},
70-
/**
71-
* Gets the stored type of the variable indicated in the argument. As only one
72-
* variable is stored in this block, no need to check input
73-
* @this Blockly.
74-
* @param {!string} varName Name of this block variable to check type.
75-
* @return {!string} String to indicate the type of this block.
76-
*/
77-
getVarType: function(varName) {
78-
//return [Blockly.Types.UNDEF, this.getFieldValue('VAR')];
79-
return Blockly.Types.getChildBlockType(this)
80-
}
42+
this.setOutput(true);
43+
this.setTooltip(Blockly.Msg.VARIABLES_GET_TOOLTIP);
44+
this.contextMenuMsg_ = Blockly.Msg.VARIABLES_GET_CREATE_SET;
45+
},
46+
contextMenuType_: 'variables_set',
47+
/**
48+
* Add menu option to create getter/setter block for this setter/getter.
49+
* @param {!Array} options List of menu options to add to.
50+
* @this Blockly.Block
51+
*/
52+
customContextMenu: function (options) {
53+
var option = {
54+
enabled: true
55+
};
56+
var name = this.getFieldValue('VAR');
57+
option.text = this.contextMenuMsg_.replace('%1', name);
58+
var xmlField = goog.dom.createDom('field', null, name);
59+
xmlField.setAttribute('name', 'VAR');
60+
var xmlBlock = goog.dom.createDom('block', null, xmlField);
61+
xmlBlock.setAttribute('type', this.contextMenuType_);
62+
option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock);
63+
options.push(option);
64+
},
65+
/**
66+
* @return {!string} Retrieves the type (stored in varType) of this block.
67+
* @this Blockly.Block
68+
*/
69+
getBlockType: function () {
70+
return [Blockly.Types.UNDEF, this.getFieldValue('VAR')];
71+
},
72+
/**
73+
* Gets the stored type of the variable indicated in the argument. As only one
74+
* variable is stored in this block, no need to check input
75+
* @this Blockly.
76+
* @param {!string} varName Name of this block variable to check type.
77+
* @return {!string} String to indicate the type of this block.
78+
*/
79+
getVarType: function (varName) {
80+
//return [Blockly.Types.UNDEF, this.getFieldValue('VAR')];
81+
return Blockly.Types.getChildBlockType(this)
82+
}
8183
};
8284

8385
Blockly.Blocks['variables_set'] = {
84-
/**
85-
* Block for variable setter.
86-
* @this Blockly.Block
87-
*/
88-
init: function() {
89-
this.appendValueInput("VALUE")
90-
.appendField(Blockly.Msg.VARIABLES_SET)
91-
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR')
92-
.appendField(Blockly.Msg._AT);
93-
this.setHelpUrl(Blockly.Msg.HELPURL);
94-
this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP);
95-
this.setColour(Blockly.Blocks.variables.HUE);
96-
this.setPreviousStatement(true, null);
97-
this.setNextStatement(true, null);
98-
this.contextMenuMsg_ = Blockly.Msg.VARIABLES_SET_CREATE_GET;
99-
},
100-
contextMenuType_: 'variables_get',
101-
customContextMenu: Blockly.Blocks['variables_get'].customContextMenu,
102-
/**
103-
* Searches through the nested blocks to find a variable type.
104-
* @this Blockly.Block
105-
* @param {!string} varName Name of this block variable to check type.
106-
* @return {string} String to indicate the type of this block.
107-
*/
108-
getVarType: function(varName) {
109-
return Blockly.Types.getChildBlockType(this);
110-
}
86+
/**
87+
* Block for variable setter.
88+
* @this Blockly.Block
89+
*/
90+
init: function () {
91+
this.appendValueInput("VALUE")
92+
.appendField(Blockly.Msg.VARIABLES_SET)
93+
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR')
94+
.appendField(Blockly.Msg._AT);
95+
this.setHelpUrl(Blockly.Msg.HELPURL);
96+
this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP);
97+
this.setColour(Blockly.Blocks.variables.HUE);
98+
this.setPreviousStatement(true, null);
99+
this.setNextStatement(true, null);
100+
this.contextMenuMsg_ = Blockly.Msg.VARIABLES_SET_CREATE_GET;
101+
},
102+
contextMenuType_: 'variables_get',
103+
customContextMenu: Blockly.Blocks['variables_get'].customContextMenu,
104+
/**
105+
* Searches through the nested blocks to find a variable type.
106+
* @this Blockly.Block
107+
* @param {!string} varName Name of this block variable to check type.
108+
* @return {string} String to indicate the type of this block.
109+
*/
110+
getVarType: function (varName) {
111+
return Blockly.Types.getChildBlockType(this);
112+
}
111113
};
112114

113115
Blockly.Blocks['variables_set_type'] = {
114-
/**
115-
* Block for variable casting.
116-
* @this Blockly.Block
117-
*/
118-
init: function() {
119-
this.setHelpUrl('http://arduino.cc/en/Reference/HomePage');
120-
this.setColour(Blockly.Blocks.variables.HUE);
121-
this.appendValueInput('VARIABLE_SETTYPE_INPUT');
122-
this.appendDummyInput()
116+
/**
117+
* Block for variable casting.
118+
* @this Blockly.Block
119+
*/
120+
init: function () {
121+
this.setHelpUrl('http://arduino.cc/en/Reference/HomePage');
122+
this.setColour(Blockly.Blocks.variables.HUE);
123+
this.appendValueInput('VARIABLE_SETTYPE_INPUT');
124+
this.appendDummyInput()
123125
.appendField(Blockly.Msg.VARIABLES_AS)
124126
.appendField(new Blockly.FieldDropdown(
125-
Blockly.Types.getValidTypeArray()), 'VARIABLE_SETTYPE_TYPE');
126-
this.setInputsInline(true);
127-
this.setOutput(true);
128-
this.setTooltip('Sets a value to a specific type');
129-
},
130-
/**
131-
* Assigns a type to the block based on the selected type to cast.
132-
* @return {!string} Blockly type for this block configuration.
133-
* @this Blockly.Block
134-
*/
135-
getBlockType: function() {
136-
var blocklyTypeKey = this.getFieldValue('VARIABLE_SETTYPE_TYPE');
137-
return Blockly.Types[blocklyTypeKey];
138-
}
127+
Blockly.Types.getValidTypeArray()), 'VARIABLE_SETTYPE_TYPE');
128+
this.setInputsInline(true);
129+
this.setOutput(true);
130+
this.setTooltip('Sets a value to a specific type');
131+
},
132+
/**
133+
* Assigns a type to the block based on the selected type to cast.
134+
* @return {!string} Blockly type for this block configuration.
135+
* @this Blockly.Block
136+
*/
137+
getBlockType: function () {
138+
var blocklyTypeKey = this.getFieldValue('VARIABLE_SETTYPE_TYPE');
139+
return Blockly.Types[blocklyTypeKey];
140+
}
139141
};
140142

141143
Blockly.Blocks['variables_const'] = {
142-
init: function() {
144+
init: function () {
143145
this.appendValueInput("VAL_CONST")
144-
.appendField(Blockly.Msg.VARIABLES_SET_CONST)
145-
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR')
146-
.appendField(Blockly.Msg.VARIABLES_SET_CONST_AT);
146+
.appendField(Blockly.Msg.VARIABLES_SET_CONST)
147+
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR')
148+
.appendField(Blockly.Msg.VARIABLES_SET_CONST_AT);
147149
this.setColour(Blockly.Blocks.variables.HUE);
148150
this.setPreviousStatement(true, null);
149151
this.setNextStatement(true, null);
150152
this.setTooltip(Blockly.Msg.VARIABLES_SET_CONST_TOOLTIP);
151153
this.setHelpUrl(Blockly.Msg.VARIABLES_SET_CONST_HELPURL);
152154
this.contextMenuMsg_ = Blockly.Msg.VARIABLES_SET_CREATE_GET;
153-
},
154-
contextMenuType_: 'variables_get',
155-
customContextMenu: Blockly.Blocks['variables_get'].customContextMenu,
156-
/**
157-
* Searches through the nested blocks to find a variable type.
158-
* @this Blockly.Block
159-
* @param {!string} varName Name of this block variable to check type.
160-
* @return {string} String to indicate the type of this block.
161-
*/
162-
getVarType: function(varName) {
163-
return Blockly.Types.getChildBlockType(this);
164-
}
155+
},
156+
contextMenuType_: 'variables_get',
157+
customContextMenu: Blockly.Blocks['variables_get'].customContextMenu,
158+
/**
159+
* Searches through the nested blocks to find a variable type.
160+
* @this Blockly.Block
161+
* @param {!string} varName Name of this block variable to check type.
162+
* @return {string} String to indicate the type of this block.
163+
*/
164+
getVarType: function (varName) {
165+
return Blockly.Types.getChildBlockType(this);
166+
}
165167
};
166168

167169
Blockly.Blocks['variables_set_init'] = {
168-
init: function() {
170+
init: function () {
169171
this.appendValueInput("VALUE")
170-
.appendField(Blockly.Msg.VARIABLES_SET_INIT)
171-
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR')
172-
.appendField(Blockly.Msg.VARIABLES_AS)
173-
.appendField(new Blockly.FieldDropdown(Blockly.Types.getValidTypeArray()), 'VARIABLE_SETTYPE_TYPE')
174-
.appendField(Blockly.Msg._AT);
172+
.appendField(Blockly.Msg.VARIABLES_SET_INIT)
173+
.appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_DEFAULT_NAME), 'VAR')
174+
.appendField(Blockly.Msg.VARIABLES_AS)
175+
.appendField(new Blockly.FieldDropdown(Blockly.Types.getValidTypeArray()), 'VARIABLE_SETTYPE_TYPE')
176+
.appendField(Blockly.Msg._AT);
175177
this.setPreviousStatement(true, null);
176178
this.setNextStatement(true, null);
177179
this.setColour(Blockly.Blocks.variables.HUE);
@@ -187,7 +189,7 @@ Blockly.Blocks['variables_set_init'] = {
187189
* @param {!string} varName Name of this block variable to check type.
188190
* @return {string} String to indicate the type of this block.
189191
*/
190-
getVarType: function(varName) {
191-
return Blockly.Types.getChildBlockType(this);
192+
getVarType: function (varName) {
193+
return Blockly.Types.getChildBlockType(this);
192194
}
193-
};
195+
};

www/generators/BlocklyArduino/variables.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ goog.provide('Blockly.Arduino.variables');
2828
goog.require('Blockly.Arduino');
2929

3030

31-
Blockly.Arduino.variables_get = function(block) {
31+
Blockly.Arduino['variables_get'] = function(block) {
3232
var code = Blockly.Arduino.variableDB_.getName(block.getFieldValue('VAR'),Blockly.Variables.NAME_TYPE);
3333
return [code, Blockly.Arduino.ORDER_ATOMIC];
3434
};
@@ -40,23 +40,25 @@ Blockly.Arduino['variables_set_type'] = function(block) {
4040
return [code, Blockly.Arduino.ORDER_ATOMIC];
4141
};
4242

43-
Blockly.Arduino.variables_set = function(block) {
43+
Blockly.Arduino['variables_set'] = function(block) {
4444
var argument0 = Blockly.Arduino.valueToCode(block, 'VALUE', Blockly.Arduino.ORDER_ASSIGNMENT) || '0';
4545
var varName = Blockly.Arduino.variableDB_.getName(block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
4646
var code = varName + ' = ' + argument0 + ';\n';
4747
return code;
4848
};
4949

50-
Blockly.Arduino.variables_const = function(block) {
50+
Blockly.Arduino['variables_const'] = function(block) {
5151
var argument0 = Blockly.Arduino.valueToCode(block, 'VALUE', Blockly.Arduino.ORDER_ASSIGNMENT) || '0';
5252
var varName = Blockly.Arduino.variableDB_.getName(block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
5353
var typeBlock = Blockly.Arduino.getArduinoType_(Blockly.Types.getChildBlockType(block));
5454
Blockly.Arduino.variables_[varName] = 'const ' + typeBlock + ' ' + varName + ' = ' + argument0 + ';';
55+
return '';
5556
};
5657

5758
Blockly.Arduino['variables_set_init'] = function(block){
5859
var argument0 = Blockly.Arduino.valueToCode(block, 'VALUE', Blockly.Arduino.ORDER_ASSIGNMENT) || '0';
5960
var varName = Blockly.Arduino.variableDB_.getName(block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
6061
var varType = Blockly.Arduino.getArduinoType_(Blockly.Types[block.getFieldValue('VARIABLE_SETTYPE_TYPE')]);
6162
Blockly.Arduino.variables_[varName] = varType + ' ' + varName + ' = ' + argument0 + ';';
63+
return '';
6264
};

www/lang/BlocklyArduino_msg/UI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
var BlocklyArduinoMSG = {
2-
span_version: "<i>version 23-10-2020 - v3.2.8</i>",
2+
span_version: "<i>version 01-11-2020 - v3.2.9</i>",
33
};

www/sync.ffs_db

6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)