@@ -85,7 +85,6 @@ interface CallPythonFunctionMixin extends CallPythonFunctionMixinType {
85
85
mrcComponentClassName : string ,
86
86
mrcOriginalComponentName : string ,
87
87
mrcMechanismClassName : string ,
88
- mrcComponentNames : string [ ] ,
89
88
mrcMapComponentNameToId : { [ componentName : string ] : string } ,
90
89
}
91
90
type CallPythonFunctionMixinType = typeof CALL_PYTHON_FUNCTION ;
@@ -167,65 +166,88 @@ const CALL_PYTHON_FUNCTION = {
167
166
switch ( this . mrcFunctionKind ) {
168
167
case FunctionKind . BUILT_IN : {
169
168
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
170
- tooltip = 'Calls the builtin function ' + functionName + '.' ;
169
+ tooltip = Blockly . Msg . CALL_BUILTIN_FUNCTION_TOOLTIP ;
170
+ tooltip = tooltip . replace ( '{{functionName}}' , functionName ) ;
171
171
break ;
172
172
}
173
173
case FunctionKind . MODULE : {
174
174
const moduleName = this . getFieldValue ( FIELD_MODULE_OR_CLASS_NAME ) ;
175
175
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
176
- tooltip = 'Calls the module function ' + moduleName + '.' + functionName + '.' ;
176
+ tooltip = Blockly . Msg . CALL_MODULE_FUNCTION_TOOLTIP ;
177
+ tooltip = tooltip
178
+ . replace ( '{{moduleName}}' , moduleName )
179
+ . replace ( '{{functionName}}' , functionName ) ;
177
180
break ;
178
181
}
179
182
case FunctionKind . STATIC : {
180
183
const className = this . getFieldValue ( FIELD_MODULE_OR_CLASS_NAME ) ;
181
184
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
182
- tooltip = 'Calls the static method ' + className + '.' + functionName + '.' ;
185
+ tooltip = Blockly . Msg . CALL_STATIC_METHOD_TOOLTIP ;
186
+ tooltip = tooltip
187
+ . replace ( '{{className}}' , className )
188
+ . replace ( '{{functionName}}' , functionName ) ;
183
189
break ;
184
190
}
185
191
case FunctionKind . CONSTRUCTOR : {
186
192
const className = this . getFieldValue ( FIELD_MODULE_OR_CLASS_NAME ) ;
187
- tooltip = 'Constructs an instance of the class ' + className + '.' ;
193
+ tooltip = Blockly . Msg . CALL_CONSTRUCTOR_TOOLTIP ;
194
+ tooltip = tooltip . replace ( '{{className}}' , className ) ;
188
195
break ;
189
196
}
190
197
case FunctionKind . INSTANCE : {
191
198
const className = this . getFieldValue ( FIELD_MODULE_OR_CLASS_NAME ) ;
192
199
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
193
- tooltip = 'Calls the instance method ' + className + '.' + functionName + '.' ;
200
+ tooltip = Blockly . Msg . CALL_INSTANCE_METHOD_TOOLTIP ;
201
+ tooltip = tooltip
202
+ . replace ( '{{className}}' , className )
203
+ . replace ( '{{functionName}}' , functionName ) ;
194
204
break ;
195
205
}
196
206
case FunctionKind . INSTANCE_WITHIN : {
197
207
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
198
- tooltip = 'Calls the instance method ' + functionName + '.' ;
208
+ tooltip = Blockly . Msg . CALL_INSTANCE_METHOD_WITHIN_TOOLTIP ;
209
+ tooltip = tooltip . replace ( '{{functionName}}' , functionName ) ;
199
210
break ;
200
211
}
201
212
case FunctionKind . EVENT : {
202
213
const eventName = this . getFieldValue ( FIELD_EVENT_NAME ) ;
203
- tooltip = 'Fires the event ' + eventName + '.' ;
214
+ tooltip = Blockly . Msg . CALL_INSTANCE_METHOD_WITHIN_TOOLTIP ;
215
+ tooltip = tooltip . replace ( '{{eventName}}' , eventName ) ;
204
216
break ;
205
217
}
206
218
case FunctionKind . INSTANCE_COMPONENT : {
207
219
const className = this . mrcComponentClassName ;
208
220
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
209
221
if ( this . mrcMechanismId ) {
210
- tooltip = 'Calls the instance method ' + className + '.' + functionName +
211
- ' on the component named ' + this . getFieldValue ( FIELD_COMPONENT_NAME ) +
212
- ' in the mechanism named ' + this . getFieldValue ( FIELD_MECHANISM_NAME ) + '.' ;
222
+ tooltip = Blockly . Msg . CALL_MECHANISM_COMPONENT_INSTANCE_METHOD ;
223
+ tooltip = tooltip
224
+ . replace ( '{{className}}' , className )
225
+ . replace ( '{{functionName}}' , functionName )
226
+ . replace ( '{{componentName}}' , this . getFieldValue ( FIELD_COMPONENT_NAME ) )
227
+ . replace ( '{{mechanismName}}' , this . getFieldValue ( FIELD_MECHANISM_NAME ) ) ;
213
228
} else {
214
- tooltip = 'Calls the instance method ' + className + '.' + functionName +
215
- ' on the component named ' + this . getFieldValue ( FIELD_COMPONENT_NAME ) + '.' ;
229
+ tooltip = Blockly . Msg . CALL_COMPONENT_INSTANCE_METHOD ;
230
+ tooltip = tooltip
231
+ . replace ( '{{className}}' , className )
232
+ . replace ( '{{functionName}}' , functionName )
233
+ . replace ( '{{componentName}}' , this . getFieldValue ( FIELD_COMPONENT_NAME ) ) ;
216
234
}
217
235
break ;
218
236
}
219
237
case FunctionKind . INSTANCE_ROBOT : {
220
238
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
221
- tooltip = 'Calls the robot method ' + functionName + '.' ;
239
+ tooltip = Blockly . Msg . CALL_INSTANCE_METHOD_WITHIN_TOOLTIP ;
240
+ tooltip = tooltip . replace ( '{{functionName}}' , functionName ) ;
222
241
break ;
223
242
}
224
243
case FunctionKind . INSTANCE_MECHANISM : {
225
244
const className = this . mrcMechanismClassName ;
226
245
const functionName = this . getFieldValue ( FIELD_FUNCTION_NAME ) ;
227
- tooltip = 'Calls the instance method ' + className + '.' + functionName +
228
- ' on the mechanism named ' + this . getFieldValue ( FIELD_MECHANISM_NAME ) + '.' ;
246
+ tooltip = Blockly . Msg . CALL_MECHANISM_INSTANCE_METHOD ;
247
+ tooltip = tooltip
248
+ . replace ( '{{className}}' , className )
249
+ . replace ( '{{functionName}}' , functionName )
250
+ . replace ( '{{mechanismName}}' , this . getFieldValue ( FIELD_MECHANISM_NAME ) ) ;
229
251
break ;
230
252
}
231
253
default :
@@ -318,8 +340,7 @@ const CALL_PYTHON_FUNCTION = {
318
340
this . mrcMechanismId = extraState . mechanismId ? extraState . mechanismId : '' ;
319
341
this . mrcComponentClassName = extraState . componentClassName ? extraState . componentClassName : '' ;
320
342
this . mrcMechanismClassName = extraState . mechanismClassName ? extraState . mechanismClassName : '' ;
321
- // Initialize mrcComponentNames and mrcMapComponentNameToId here. They will be filled during mrcValidate.
322
- this . mrcComponentNames = [ ] ;
343
+ // Initialize mrcMapComponentNameToId here. It will be filled during mrcValidate.
323
344
this . mrcMapComponentNameToId = { } ;
324
345
this . updateBlock_ ( ) ;
325
346
} ,
@@ -349,31 +370,31 @@ const CALL_PYTHON_FUNCTION = {
349
370
switch ( this . mrcFunctionKind ) {
350
371
case FunctionKind . BUILT_IN :
351
372
this . appendDummyInput ( INPUT_TITLE )
352
- . appendField ( 'call' )
373
+ . appendField ( Blockly . Msg . CALL )
353
374
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
354
375
break ;
355
376
case FunctionKind . MODULE :
356
377
this . appendDummyInput ( INPUT_TITLE )
357
- . appendField ( 'call' )
378
+ . appendField ( Blockly . Msg . CALL )
358
379
. appendField ( createFieldNonEditableText ( '' ) , FIELD_MODULE_OR_CLASS_NAME )
359
380
. appendField ( '.' )
360
381
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
361
382
break ;
362
383
case FunctionKind . STATIC :
363
384
this . appendDummyInput ( INPUT_TITLE )
364
- . appendField ( 'call' )
385
+ . appendField ( Blockly . Msg . CALL )
365
386
. appendField ( createFieldNonEditableText ( '' ) , FIELD_MODULE_OR_CLASS_NAME )
366
387
. appendField ( '.' )
367
388
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
368
389
break ;
369
390
case FunctionKind . CONSTRUCTOR :
370
391
this . appendDummyInput ( INPUT_TITLE )
371
- . appendField ( 'create' )
392
+ . appendField ( Blockly . Msg . CREATE )
372
393
. appendField ( createFieldNonEditableText ( '' ) , FIELD_MODULE_OR_CLASS_NAME ) ;
373
394
break ;
374
395
case FunctionKind . INSTANCE :
375
396
this . appendDummyInput ( INPUT_TITLE )
376
- . appendField ( 'call' )
397
+ . appendField ( Blockly . Msg . CALL )
377
398
. appendField ( createFieldNonEditableText ( '' ) , FIELD_MODULE_OR_CLASS_NAME )
378
399
. appendField ( '.' )
379
400
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
@@ -382,7 +403,7 @@ const CALL_PYTHON_FUNCTION = {
382
403
const input = this . getInput ( INPUT_TITLE ) ;
383
404
if ( ! input ) {
384
405
this . appendDummyInput ( INPUT_TITLE )
385
- . appendField ( 'call' )
406
+ . appendField ( Blockly . Msg . CALL )
386
407
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
387
408
}
388
409
break ;
@@ -391,14 +412,14 @@ const CALL_PYTHON_FUNCTION = {
391
412
const input = this . getInput ( INPUT_TITLE ) ;
392
413
if ( ! input ) {
393
414
this . appendDummyInput ( INPUT_TITLE )
394
- . appendField ( 'fire' )
415
+ . appendField ( Blockly . Msg . FIRE )
395
416
. appendField ( createFieldNonEditableText ( '' ) , FIELD_EVENT_NAME ) ;
396
417
}
397
418
break ;
398
419
}
399
420
case FunctionKind . INSTANCE_COMPONENT : {
400
421
const titleInput = this . appendDummyInput ( INPUT_TITLE )
401
- . appendField ( 'call' ) ;
422
+ . appendField ( Blockly . Msg . CALL ) ;
402
423
if ( this . mrcMechanismId ) {
403
424
titleInput
404
425
. appendField ( createFieldNonEditableText ( '' ) , FIELD_MECHANISM_NAME )
@@ -414,15 +435,15 @@ const CALL_PYTHON_FUNCTION = {
414
435
}
415
436
case FunctionKind . INSTANCE_ROBOT : {
416
437
this . appendDummyInput ( INPUT_TITLE )
417
- . appendField ( 'call' )
418
- . appendField ( createFieldNonEditableText ( 'robot' ) )
438
+ . appendField ( Blockly . Msg . CALL )
439
+ . appendField ( createFieldNonEditableText ( Blockly . Msg . ROBOT ) )
419
440
. appendField ( '.' )
420
441
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
421
442
break ;
422
443
}
423
444
case FunctionKind . INSTANCE_MECHANISM : {
424
445
this . appendDummyInput ( INPUT_TITLE )
425
- . appendField ( 'call' )
446
+ . appendField ( Blockly . Msg . CALL )
426
447
. appendField ( createFieldNonEditableText ( '' ) , FIELD_MECHANISM_NAME )
427
448
. appendField ( '.' )
428
449
. appendField ( createFieldNonEditableText ( '' ) , FIELD_FUNCTION_NAME ) ;
@@ -505,7 +526,7 @@ const CALL_PYTHON_FUNCTION = {
505
526
methodOrEvent : storageModuleContent . Method | storageModuleContent . Event
506
527
) : void {
507
528
// mutateMethodCaller is called when the method or event definition block in the same module is modified.
508
- if ( this . mrcFunctionKind == FunctionKind . EVENT ) {
529
+ if ( this . mrcFunctionKind === FunctionKind . EVENT ) {
509
530
const event = methodOrEvent as storageModuleContent . Event ;
510
531
this . mrcArgs = [ ] ;
511
532
event . args . forEach ( ( arg ) => {
@@ -514,7 +535,7 @@ const CALL_PYTHON_FUNCTION = {
514
535
type : arg . type ,
515
536
} ) ;
516
537
} ) ;
517
- } else if ( this . mrcFunctionKind == FunctionKind . INSTANCE_WITHIN ) {
538
+ } else if ( this . mrcFunctionKind === FunctionKind . INSTANCE_WITHIN ) {
518
539
const method = methodOrEvent as storageModuleContent . Method ;
519
540
this . mrcReturnType = method . returnType ;
520
541
this . mrcArgs = [ ] ;
@@ -591,12 +612,14 @@ const CALL_PYTHON_FUNCTION = {
591
612
// If the component belongs to a mechanism, also check whether the mechanism
592
613
// still exists and whether it has been changed.
593
614
if ( this . mrcFunctionKind === FunctionKind . INSTANCE_COMPONENT ) {
615
+ const componentNames : string [ ] = [ ] ;
616
+ this . mrcMapComponentNameToId = { }
594
617
this . getComponents ( ) . forEach ( component => {
595
- this . mrcComponentNames . push ( component . name ) ;
618
+ componentNames . push ( component . name ) ;
596
619
this . mrcMapComponentNameToId [ component . name ] = component . componentId ;
597
620
} ) ;
598
621
let foundComponent = false ;
599
- for ( const componentName of this . mrcComponentNames ) {
622
+ for ( const componentName of componentNames ) {
600
623
const componentId = this . mrcMapComponentNameToId [ componentName ] ;
601
624
if ( componentId === this . mrcComponentId ) {
602
625
foundComponent = true ;
@@ -615,12 +638,12 @@ const CALL_PYTHON_FUNCTION = {
615
638
break ;
616
639
}
617
640
}
618
- if ( indexOfComponentNameField == - 1 ) {
641
+ if ( indexOfComponentNameField === - 1 ) {
619
642
throw new Error ( 'Could not find the component name field' ) ;
620
643
}
621
644
titleInput . removeField ( FIELD_COMPONENT_NAME ) ;
622
645
titleInput . insertFieldAt ( indexOfComponentNameField ,
623
- createFieldDropdown ( this . mrcComponentNames ) , FIELD_COMPONENT_NAME ) ;
646
+ createFieldDropdown ( componentNames ) , FIELD_COMPONENT_NAME ) ;
624
647
// TODO(lizlooney): If the current module is the robot or a mechanism, we need to update the
625
648
// items in the dropdown if the user adds or removes a component.
626
649
@@ -631,7 +654,39 @@ const CALL_PYTHON_FUNCTION = {
631
654
}
632
655
}
633
656
if ( ! foundComponent ) {
634
- warnings . push ( 'This block calls a method on a component that no longer exists.' ) ;
657
+ if ( this . mrcMechanismId ) {
658
+ // Check whether the the component still exists, but is a private component in the mechanism.
659
+ for ( const mechanismInRobot of editor . getMechanismsFromRobot ( ) ) {
660
+ if ( mechanismInRobot . mechanismId === this . mrcMechanismId ) {
661
+ for ( const mechanism of editor . getMechanisms ( ) ) {
662
+ if ( mechanism . moduleId === mechanismInRobot . moduleId ) {
663
+ for ( const privateComponent of editor . getPrivateComponentsFromMechanism ( mechanism ) ) {
664
+ if ( privateComponent . className === this . mrcComponentClassName &&
665
+ privateComponent . componentId === this . mrcComponentId ) {
666
+ foundComponent = true ;
667
+ let warning = Blockly . Msg . WARNING_CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT ;
668
+ warning = warning . replace ( '{{mechanismClassName}}' , mechanism . className ) ;
669
+ warnings . push ( warning ) ;
670
+ break
671
+ }
672
+ }
673
+ break ;
674
+ }
675
+ if ( foundComponent ) {
676
+ break ;
677
+ }
678
+ }
679
+ break ;
680
+ }
681
+ if ( foundComponent ) {
682
+ break ;
683
+ }
684
+ }
685
+ }
686
+ }
687
+
688
+ if ( ! foundComponent ) {
689
+ warnings . push ( Blockly . Msg . WARNING_CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT ) ;
635
690
}
636
691
637
692
if ( this . mrcMechanismId ) {
@@ -649,9 +704,7 @@ const CALL_PYTHON_FUNCTION = {
649
704
}
650
705
}
651
706
if ( ! foundMechanism ) {
652
- warnings . push (
653
- 'This block calls a method on a component that belongs to a mechanism that no ' +
654
- 'longer exists.' ) ;
707
+ warnings . push ( Blockly . Msg . WARNING_CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM ) ;
655
708
}
656
709
}
657
710
@@ -665,7 +718,7 @@ const CALL_PYTHON_FUNCTION = {
665
718
// visible warning on it.
666
719
if ( this . mrcFunctionKind === FunctionKind . INSTANCE_ROBOT ) {
667
720
if ( editor . getModuleType ( ) === storageModule . ModuleType . MECHANISM ) {
668
- warnings . push ( 'This block is not allowed to be used inside a mechanism.' ) ;
721
+ warnings . push ( Blockly . Msg . WARNING_CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM ) ;
669
722
} else {
670
723
let foundRobotMethod = false ;
671
724
const robotMethods = editor . getMethodsFromRobot ( ) ;
@@ -695,7 +748,7 @@ const CALL_PYTHON_FUNCTION = {
695
748
}
696
749
}
697
750
if ( ! foundRobotMethod ) {
698
- warnings . push ( 'This block calls a method that no longer exists.' ) ;
751
+ warnings . push ( Blockly . Msg . WARNING_CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD ) ;
699
752
}
700
753
}
701
754
}
@@ -711,7 +764,7 @@ const CALL_PYTHON_FUNCTION = {
711
764
// visible warning on it.
712
765
if ( this . mrcFunctionKind === FunctionKind . INSTANCE_MECHANISM ) {
713
766
if ( editor . getModuleType ( ) === storageModule . ModuleType . MECHANISM ) {
714
- warnings . push ( 'This block is not allowed to be used inside a mechanism.' ) ;
767
+ warnings . push ( Blockly . Msg . WARNING_CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM ) ;
715
768
} else {
716
769
let foundMechanism = false ;
717
770
const mechanismsInRobot = editor . getMechanismsFromRobot ( ) ;
@@ -753,15 +806,15 @@ const CALL_PYTHON_FUNCTION = {
753
806
}
754
807
}
755
808
if ( ! foundMechanismMethod ) {
756
- warnings . push ( 'This block calls a method that no longer exists.' ) ;
809
+ warnings . push ( Blockly . Msg . WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD ) ;
757
810
}
758
811
759
812
// Since we found the mechanism, we can break out of the loop.
760
813
break ;
761
814
}
762
815
}
763
816
if ( ! foundMechanism ) {
764
- warnings . push ( 'This block calls a method in a mechanism that no longer exists.' ) ;
817
+ warnings . push ( Blockly . Msg . WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM ) ;
765
818
}
766
819
}
767
820
}
0 commit comments