@@ -38,6 +38,7 @@ import { MUTATOR_BLOCK_NAME, PARAM_CONTAINER_BLOCK_NAME, MethodMutatorArgBlock }
3838export const BLOCK_NAME = 'mrc_class_method_def' ;
3939
4040export const FIELD_METHOD_NAME = 'NAME' ;
41+ export const RETURN_VALUE = 'RETURN' ;
4142
4243type Parameter = {
4344 name : string ,
@@ -54,6 +55,7 @@ interface ClassMethodDefMixin extends ClassMethodDefMixinType {
5455 mrcParameters : Parameter [ ] ,
5556 mrcPythonMethodName : string ,
5657 mrcFuncName : string | null ,
58+ mrcUpdateReturnInput ( ) : void ,
5759}
5860type ClassMethodDefMixinType = typeof CLASS_METHOD_DEF ;
5961
@@ -179,6 +181,7 @@ const CLASS_METHOD_DEF = {
179181 ( this as Blockly . BlockSvg ) . setMutator ( null ) ;
180182 }
181183 this . mrcUpdateParams ( ) ;
184+ this . mrcUpdateReturnInput ( ) ;
182185 } ,
183186 compose : function ( this : ClassMethodDefBlock , containerBlock : any ) {
184187 // Parameter list.
@@ -250,6 +253,21 @@ const CLASS_METHOD_DEF = {
250253 }
251254 }
252255 } ,
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+ } ,
253271 removeParameterFields : function ( input : Blockly . Input ) {
254272 const fieldsToRemove = input . fieldRow
255273 . filter ( field => field . name ?. startsWith ( 'PARAM_' ) )
@@ -502,6 +520,23 @@ export function createCustomMethodBlock(): toolboxItems.Block {
502520 return new toolboxItems . Block ( BLOCK_NAME , extraState , fields , null ) ;
503521}
504522
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+
505540export function getBaseClassBlocks (
506541 baseClassName : string ) : toolboxItems . Block [ ] {
507542 const blocks : toolboxItems . Block [ ] = [ ] ;
0 commit comments