@@ -38,6 +38,7 @@ import { MUTATOR_BLOCK_NAME, PARAM_CONTAINER_BLOCK_NAME, MethodMutatorArgBlock }
38
38
export const BLOCK_NAME = 'mrc_class_method_def' ;
39
39
40
40
export const FIELD_METHOD_NAME = 'NAME' ;
41
+ export const RETURN_VALUE = 'RETURN' ;
41
42
42
43
type Parameter = {
43
44
name : string ,
@@ -54,6 +55,7 @@ interface ClassMethodDefMixin extends ClassMethodDefMixinType {
54
55
mrcParameters : Parameter [ ] ,
55
56
mrcPythonMethodName : string ,
56
57
mrcFuncName : string | null ,
58
+ mrcUpdateReturnInput ( ) : void ,
57
59
}
58
60
type ClassMethodDefMixinType = typeof CLASS_METHOD_DEF ;
59
61
@@ -179,6 +181,7 @@ const CLASS_METHOD_DEF = {
179
181
( this as Blockly . BlockSvg ) . setMutator ( null ) ;
180
182
}
181
183
this . mrcUpdateParams ( ) ;
184
+ this . mrcUpdateReturnInput ( ) ;
182
185
} ,
183
186
compose : function ( this : ClassMethodDefBlock , containerBlock : any ) {
184
187
// Parameter list.
@@ -250,6 +253,21 @@ const CLASS_METHOD_DEF = {
250
253
}
251
254
}
252
255
} ,
256
+ mrcUpdateReturnInput : function ( this : ClassMethodDefBlock ) {
257
+ // Remove existing return input if it exists
258
+ if ( this . getInput ( RETURN_VALUE ) ) {
259
+ this . removeInput ( RETURN_VALUE ) ;
260
+ }
261
+
262
+ // Add return input if return type is not 'None'
263
+ if ( this . mrcReturnType && this . mrcReturnType !== 'None' ) {
264
+ this . appendValueInput ( RETURN_VALUE )
265
+ . setAlign ( Blockly . inputs . Align . RIGHT )
266
+ . appendField ( Blockly . Msg . PROCEDURES_DEFRETURN_RETURN ) ;
267
+ // Move the return input to be after the statement input
268
+ this . moveInputBefore ( 'STACK' , RETURN_VALUE ) ;
269
+ }
270
+ } ,
253
271
removeParameterFields : function ( input : Blockly . Input ) {
254
272
const fieldsToRemove = input . fieldRow
255
273
. filter ( field => field . name ?. startsWith ( 'PARAM_' ) )
@@ -502,6 +520,23 @@ export function createCustomMethodBlock(): toolboxItems.Block {
502
520
return new toolboxItems . Block ( BLOCK_NAME , extraState , fields , null ) ;
503
521
}
504
522
523
+ export function createCustomMethodBlockWithReturn ( ) : toolboxItems . Block {
524
+ const extraState : ClassMethodDefExtraState = {
525
+ canChangeSignature : true ,
526
+ canBeCalledWithinClass : true ,
527
+ canBeCalledOutsideClass : true ,
528
+ returnType : 'Any' ,
529
+ params : [ ] ,
530
+ } ;
531
+ const fields : { [ key : string ] : any } = { } ;
532
+ fields [ FIELD_METHOD_NAME ] = 'my_method_with_return' ;
533
+ const inputs : { [ key : string ] : any } = { } ;
534
+ inputs [ RETURN_VALUE ] = {
535
+ 'type' : 'input_value' ,
536
+ } ;
537
+ return new toolboxItems . Block ( BLOCK_NAME , extraState , fields , inputs ) ;
538
+ }
539
+
505
540
export function getBaseClassBlocks (
506
541
baseClassName : string ) : toolboxItems . Block [ ] {
507
542
const blocks : toolboxItems . Block [ ] = [ ] ;
0 commit comments