fix variable naming
This commit is contained in:
		
							parent
							
								
									255b1619b8
								
							
						
					
					
						commit
						6b12c501a0
					
				| @ -1,36 +1,44 @@ | |||||||
| import Blockly from 'blockly'; | import Blockly from "blockly"; | ||||||
| 
 | 
 | ||||||
| const setVariableFunction = function (defaultValue) { | const setVariableFunction = function (defaultValue) { | ||||||
|   return function (block) { |   return function (block) { | ||||||
|         const variableName = Blockly['Arduino'].variableDB_.getName( |     const variableName = Blockly["Arduino"].variableDB_.getName( | ||||||
|             block.getFieldValue('VAR'), |       block.getFieldValue("VAR"), | ||||||
|       Blockly.Variables.NAME_TYPE |       Blockly.Variables.NAME_TYPE | ||||||
|     ); |     ); | ||||||
|         const variableValue = Blockly['Arduino'].valueToCode( |     const variableValue = Blockly["Arduino"].valueToCode( | ||||||
|       block, |       block, | ||||||
|             'VALUE', |       "VALUE", | ||||||
|             Blockly['Arduino'].ORDER_ATOMIC |       Blockly["Arduino"].ORDER_ATOMIC | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|         const allVars = Blockly.getMainWorkspace().getVariableMap().getAllVariables(); |     const allVars = Blockly.getMainWorkspace() | ||||||
|         const myVar = allVars.filter(v => v.name === variableName)[0] |       .getVariableMap() | ||||||
|         var code = '' |       .getAllVariables(); | ||||||
|  |     const myVar = allVars.filter((v) => v.name === variableName)[0]; | ||||||
|  |     var code = ""; | ||||||
| 
 | 
 | ||||||
|     switch (myVar.type) { |     switch (myVar.type) { | ||||||
|       default: |       default: | ||||||
|                 Blockly.Arduino.variables_[myVar + myVar.type] = myVar.type + " " + myVar.name + ';\n'; |         Blockly.Arduino.variables_[variableName + myVar.type] = | ||||||
|                 code = variableName + ' = ' + (variableValue || defaultValue) + ';\n'; |           myVar.type + " " + myVar.name + ";\n"; | ||||||
|  |         code = variableName + " = " + (variableValue || defaultValue) + ";\n"; | ||||||
|         break; |         break; | ||||||
|             case 'Array': |       case "Array": | ||||||
|         var arrayType; |         var arrayType; | ||||||
|         var number; |         var number; | ||||||
| 
 | 
 | ||||||
|         if (this.getChildren().length > 0) { |         if (this.getChildren().length > 0) { | ||||||
|                     if (this.getChildren()[0].type === 'lists_create_empty') { |           if (this.getChildren()[0].type === "lists_create_empty") { | ||||||
| 
 |             arrayType = this.getChildren()[0].getFieldValue("type"); | ||||||
|                         arrayType = this.getChildren()[0].getFieldValue('type'); |             number = Blockly.Arduino.valueToCode( | ||||||
|                         number = Blockly.Arduino.valueToCode(this.getChildren()[0], 'NUMBER', Blockly['Arduino'].ORDER_ATOMIC); |               this.getChildren()[0], | ||||||
|                         Blockly.Arduino.variables_[myVar + myVar.type] = `${arrayType} ${myVar.name} [${number}];\n`; |               "NUMBER", | ||||||
|  |               Blockly["Arduino"].ORDER_ATOMIC | ||||||
|  |             ); | ||||||
|  |             Blockly.Arduino.variables_[ | ||||||
|  |               myVar + myVar.type | ||||||
|  |             ] = `${arrayType} ${myVar.name} [${number}];\n`; | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
| @ -40,13 +48,13 @@ const setVariableFunction = function (defaultValue) { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const getVariableFunction = function (block) { | const getVariableFunction = function (block) { | ||||||
|     const variableName = Blockly['Arduino'].variableDB_.getName( |   const variableName = Blockly["Arduino"].variableDB_.getName( | ||||||
|         block.getFieldValue('VAR'), |     block.getFieldValue("VAR"), | ||||||
|     Blockly.Variables.NAME_TYPE |     Blockly.Variables.NAME_TYPE | ||||||
|   ); |   ); | ||||||
|   var code = variableName; |   var code = variableName; | ||||||
|     return [code, Blockly['Arduino'].ORDER_ATOMIC]; |   return [code, Blockly["Arduino"].ORDER_ATOMIC]; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| Blockly['Arduino']['variables_set_dynamic'] = setVariableFunction() | Blockly["Arduino"]["variables_set_dynamic"] = setVariableFunction(); | ||||||
| Blockly['Arduino']['variables_get_dynamic'] = getVariableFunction; | Blockly["Arduino"]["variables_get_dynamic"] = getVariableFunction; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user