@@ -26,15 +26,15 @@ import { Order } from 'blockly/python';
2626import { ClassMethodDefExtraState } from './mrc_class_method_def'
2727import { getClassData , getAllowedTypesForSetCheck , getOutputCheck } from './utils/python' ;
2828import { FunctionData , findSuperFunctionData } from './utils/python_json_types' ;
29- import * as value from './utils/value' ;
30- import * as variable from './utils/variable' ;
29+ import * as Value from './utils/value' ;
30+ import * as Variable from './utils/variable' ;
3131import { Editor } from '../editor/editor' ;
3232import { ExtendedPythonGenerator } from '../editor/extended_python_generator' ;
3333import { createFieldDropdown } from '../fields/FieldDropdown' ;
3434import { createFieldNonEditableText } from '../fields/FieldNonEditableText' ;
3535import { MRC_STYLE_FUNCTIONS } from '../themes/styles'
36- import * as toolboxItems from '../toolbox/items' ;
37- import * as commonStorage from '../storage/common_storage' ;
36+ import * as ToolboxItems from '../toolbox/items' ;
37+ import * as CommonStorage from '../storage/common_storage' ;
3838
3939
4040// A block to call a python function.
@@ -67,7 +67,7 @@ export type FunctionArg = {
6767export function addModuleFunctionBlocks (
6868 moduleName : string ,
6969 functions : FunctionData [ ] ,
70- contents : toolboxItems . ContentsType [ ] ) {
70+ contents : ToolboxItems . ContentsType [ ] ) {
7171 for ( const functionData of functions ) {
7272 const block = createModuleFunctionOrStaticMethodBlock (
7373 FunctionKind . MODULE , moduleName , moduleName , functionData ) ;
@@ -78,7 +78,7 @@ export function addModuleFunctionBlocks(
7878export function addStaticMethodBlocks (
7979 importModule : string ,
8080 functions : FunctionData [ ] ,
81- contents : toolboxItems . ContentsType [ ] ) {
81+ contents : ToolboxItems . ContentsType [ ] ) {
8282 for ( const functionData of functions ) {
8383 if ( functionData . declaringClassName ) {
8484 const block = createModuleFunctionOrStaticMethodBlock (
@@ -92,7 +92,7 @@ function createModuleFunctionOrStaticMethodBlock(
9292 functionKind : FunctionKind ,
9393 importModule : string ,
9494 moduleOrClassName : string ,
95- functionData : FunctionData ) : toolboxItems . Block {
95+ functionData : FunctionData ) : ToolboxItems . Block {
9696 const extraState : CallPythonFunctionExtraState = {
9797 functionKind : functionKind ,
9898 returnType : functionData . returnType ,
@@ -111,16 +111,16 @@ function createModuleFunctionOrStaticMethodBlock(
111111 'type' : argData . type ,
112112 } ) ;
113113 // Check if we should plug a variable getter block into the argument input socket.
114- const input = value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
114+ const input = Value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
115115 if ( input ) {
116116 inputs [ 'ARG' + i ] = input ;
117117 }
118118 }
119- let block = new toolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
119+ let block = new ToolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
120120 if ( functionData . returnType && functionData . returnType != 'None' ) {
121- const varName = variable . varNameForType ( functionData . returnType ) ;
121+ const varName = Variable . varNameForType ( functionData . returnType ) ;
122122 if ( varName ) {
123- block = variable . createVariableSetterBlock ( varName , block ) ;
123+ block = Variable . createVariableSetterBlock ( varName , block ) ;
124124 }
125125 }
126126 return block ;
@@ -129,7 +129,7 @@ function createModuleFunctionOrStaticMethodBlock(
129129export function addConstructorBlocks (
130130 importModule : string ,
131131 functions : FunctionData [ ] ,
132- contents : toolboxItems . ContentsType [ ] ) {
132+ contents : ToolboxItems . ContentsType [ ] ) {
133133 for ( const functionData of functions ) {
134134 const block = createConstructorBlock ( importModule , functionData ) ;
135135 contents . push ( block ) ;
@@ -138,7 +138,7 @@ export function addConstructorBlocks(
138138
139139function createConstructorBlock (
140140 importModule : string ,
141- functionData : FunctionData ) : toolboxItems . Block {
141+ functionData : FunctionData ) : ToolboxItems . Block {
142142 const extraState : CallPythonFunctionExtraState = {
143143 functionKind : FunctionKind . CONSTRUCTOR ,
144144 returnType : functionData . returnType ,
@@ -156,32 +156,32 @@ function createConstructorBlock(
156156 'type' : argData . type ,
157157 } ) ;
158158 // Check if we should plug a variable getter block into the argument input socket.
159- const input = value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
159+ const input = Value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
160160 if ( input ) {
161161 inputs [ 'ARG' + i ] = input ;
162162 }
163163 }
164- let block = new toolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
164+ let block = new ToolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
165165 if ( functionData . returnType && functionData . returnType != 'None' ) {
166- const varName = variable . varNameForType ( functionData . returnType ) ;
166+ const varName = Variable . varNameForType ( functionData . returnType ) ;
167167 if ( varName ) {
168- block = variable . createVariableSetterBlock ( varName , block ) ;
168+ block = Variable . createVariableSetterBlock ( varName , block ) ;
169169 }
170170 }
171171 return block ;
172172}
173173
174174export function addInstanceMethodBlocks (
175175 functions : FunctionData [ ] ,
176- contents : toolboxItems . ContentsType [ ] ) {
176+ contents : ToolboxItems . ContentsType [ ] ) {
177177 for ( const functionData of functions ) {
178178 const block = createInstanceMethodBlock ( functionData ) ;
179179 contents . push ( block ) ;
180180 }
181181}
182182
183183function createInstanceMethodBlock (
184- functionData : FunctionData ) : toolboxItems . Block {
184+ functionData : FunctionData ) : ToolboxItems . Block {
185185 const extraState : CallPythonFunctionExtraState = {
186186 functionKind : FunctionKind . INSTANCE ,
187187 returnType : functionData . returnType ,
@@ -196,32 +196,32 @@ function createInstanceMethodBlock(
196196 const argData = functionData . args [ i ] ;
197197 let argName = argData . name ;
198198 if ( i === 0 && argName === 'self' && functionData . declaringClassName ) {
199- argName = variable . getSelfArgName ( functionData . declaringClassName ) ;
199+ argName = Variable . getSelfArgName ( functionData . declaringClassName ) ;
200200 }
201201 extraState . args . push ( {
202202 'name' : argName ,
203203 'type' : argData . type ,
204204 } ) ;
205205 // Check if we should plug a variable getter block into the argument input socket.
206- const input = value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
206+ const input = Value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
207207 if ( input ) {
208208 inputs [ 'ARG' + i ] = input ;
209209 }
210210 }
211- let block = new toolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
211+ let block = new ToolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
212212 if ( functionData . returnType && functionData . returnType != 'None' ) {
213- const varName = variable . varNameForType ( functionData . returnType ) ;
213+ const varName = Variable . varNameForType ( functionData . returnType ) ;
214214 if ( varName ) {
215- block = variable . createVariableSetterBlock ( varName , block ) ;
215+ block = Variable . createVariableSetterBlock ( varName , block ) ;
216216 }
217217 }
218218 return block ;
219219}
220220
221- export function addInstanceComponentBlocks (
221+ export function getInstanceComponentBlocks (
222222 componentType : string ,
223- componentName : string ,
224- contents : toolboxItems . ContentsType [ ] ) {
223+ componentName : string ) {
224+ const contents : ToolboxItems . ContentsType [ ] = [ ] ;
225225
226226 const classData = getClassData ( componentType ) ;
227227 if ( ! classData ) {
@@ -243,10 +243,12 @@ export function addInstanceComponentBlocks(
243243 const block = createInstanceComponentBlock ( componentName , functionData ) ;
244244 contents . push ( block ) ;
245245 }
246+
247+ return contents ;
246248}
247249
248250function createInstanceComponentBlock (
249- componentName : string , functionData : FunctionData ) : toolboxItems . Block {
251+ componentName : string , functionData : FunctionData ) : ToolboxItems . Block {
250252 const extraState : CallPythonFunctionExtraState = {
251253 functionKind : FunctionKind . INSTANCE_COMPONENT ,
252254 returnType : functionData . returnType ,
@@ -271,17 +273,17 @@ function createInstanceComponentBlock(
271273 'type' : argData . type ,
272274 } ) ;
273275 // Check if we should plug a variable getter block into the argument input socket.
274- const input = value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
276+ const input = Value . valueForFunctionArgInput ( argData . type , argData . defaultValue ) ;
275277 if ( input ) {
276278 // Because we skipped the self argument, use i - 1 when filling the inputs array.
277279 inputs [ 'ARG' + ( i - 1 ) ] = input ;
278280 }
279281 }
280- let block = new toolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
282+ let block = new ToolboxItems . Block ( BLOCK_NAME , extraState , fields , Object . keys ( inputs ) . length ? inputs : null ) ;
281283 if ( functionData . returnType && functionData . returnType != 'None' ) {
282- const varName = variable . varNameForType ( functionData . returnType ) ;
284+ const varName = Variable . varNameForType ( functionData . returnType ) ;
283285 if ( varName ) {
284- block = variable . createVariableSetterBlock ( varName , block ) ;
286+ block = Variable . createVariableSetterBlock ( varName , block ) ;
285287 }
286288 }
287289 return block ;
@@ -688,11 +690,11 @@ export const pythonFromBlock = function(
688690 : block . getFieldValue ( FIELD_FUNCTION_NAME ) ;
689691 // Generate the correct code depending on the module type.
690692 switch ( generator . getModuleType ( ) ) {
691- case commonStorage . MODULE_TYPE_ROBOT :
692- case commonStorage . MODULE_TYPE_MECHANISM :
693+ case CommonStorage . MODULE_TYPE_ROBOT :
694+ case CommonStorage . MODULE_TYPE_MECHANISM :
693695 code = 'self.' ;
694696 break ;
695- case commonStorage . MODULE_TYPE_OPMODE :
697+ case CommonStorage . MODULE_TYPE_OPMODE :
696698 default :
697699 code = 'self.robot.' ;
698700 break ;
0 commit comments