@@ -118,10 +118,10 @@ type CallPythonFunctionExtraState = {
118118 actualFunctionName ?: string ,
119119 /**
120120 * The id of the block that defines the method, component, or event.
121- * For INSTANCE_WITHIN, INSTANCE_ROBOT, or INSTANCE_MECHANISM, this is the id of an
121+ * For INSTANCE_WITHIN, INSTANCE_ROBOT, or INSTANCE_MECHANISM, this is the mrcMethodId of an
122122 * mrc_class_method_def block.
123- * For INSTANCE_COMPONENT, this is the id of an mrc_component block.
124- * For EVENT, this is the id of an mrc_event block.
123+ * For INSTANCE_COMPONENT, this is the mrcComponentId of an mrc_component block.
124+ * For EVENT, this is the mrcEventId of an mrc_event block.
125125 */
126126 otherBlockId ?: string ,
127127 /**
@@ -262,7 +262,7 @@ const CALL_PYTHON_FUNCTION = {
262262 // mrc_component block that defines the component that the user has chosen.
263263 for ( const component of this . getComponentsFromRobot ( ) ) {
264264 if ( component . name == extraState . componentName ) {
265- extraState . otherBlockId = component . blockId ;
265+ extraState . otherBlockId = component . componentId ;
266266 break ;
267267 }
268268 }
@@ -455,40 +455,40 @@ const CALL_PYTHON_FUNCTION = {
455455 this . removeInput ( 'ARG' + i ) ;
456456 }
457457 } ,
458- renameMethodCaller : function ( this : CallPythonFunctionBlock , blockId : string , newName : string ) : void {
458+ renameMethodCaller : function ( this : CallPythonFunctionBlock , id : string , newName : string ) : void {
459459 // renameMethodCaller is called when a component, mechanism, event, or
460460 // method block in the same module is modified.
461461 switch ( this . mrcFunctionKind ) {
462462 case FunctionKind . INSTANCE_WITHIN :
463- if ( blockId === this . mrcOtherBlockId ) {
463+ if ( id === this . mrcOtherBlockId ) {
464464 // For INSTANCE_WITHIN this.mrcOtherBlockId is the id of an mrc_class_method_def block.
465465 this . setFieldValue ( newName , FIELD_FUNCTION_NAME ) ;
466466 // mrcActualFunctionName does not need to be updated because it is not used for INSTANCE_WITHIN.
467467 }
468468 break ;
469469 case FunctionKind . INSTANCE_COMPONENT :
470- if ( blockId === this . mrcOtherBlockId ) {
470+ if ( id === this . mrcOtherBlockId ) {
471471 // For INSTANCE_COMPONENT this.mrcOtherBlockId is the id of an mrc_component block.
472472 this . setFieldValue ( newName , FIELD_COMPONENT_NAME ) ;
473473 }
474474 break ;
475475 case FunctionKind . INSTANCE_ROBOT :
476- if ( blockId === this . mrcOtherBlockId ) {
476+ if ( id === this . mrcOtherBlockId ) {
477477 // For INSTANCE_ROBOT this.mrcOtherBlockId is the id of an mrc_class_method_def block.
478478 this . setFieldValue ( newName , FIELD_FUNCTION_NAME ) ;
479479 }
480480 break ;
481481 case FunctionKind . INSTANCE_MECHANISM :
482- if ( blockId === this . mrcOtherBlockId ) {
482+ if ( id === this . mrcOtherBlockId ) {
483483 // For INSTANCE_MECHANISM this.mrcOtherBlockId is the id of an mrc_class_method_def block.
484484 this . setFieldValue ( newName , FIELD_FUNCTION_NAME ) ;
485- } else if ( blockId === this . mrcMechanismBlockId ) {
485+ } else if ( id === this . mrcMechanismBlockId ) {
486486 // For INSTANCE_MECHANISM this.mrcMechanismBlockId is the id of an mrc_mechanism block.
487487 this . setFieldValue ( newName , FIELD_MECHANISM_NAME ) ;
488488 }
489489 break ;
490490 case FunctionKind . EVENT :
491- if ( blockId === this . mrcOtherBlockId ) {
491+ if ( id === this . mrcOtherBlockId ) {
492492 // For EVENT, this.mrcOtherBlockId is the id of an mrc_event block.
493493 this . setFieldValue ( newName , FIELD_EVENT_NAME ) ;
494494 }
@@ -557,7 +557,7 @@ const CALL_PYTHON_FUNCTION = {
557557 componentsInScope . push ( ...editor . getComponentsFromWorkspace ( ) ) ;
558558 }
559559 for ( const component of componentsInScope ) {
560- if ( component . blockId === this . mrcOtherBlockId ) {
560+ if ( component . componentId === this . mrcOtherBlockId ) {
561561 foundComponent = true ;
562562
563563 // If the component name has changed, we can handle that.
@@ -606,7 +606,7 @@ const CALL_PYTHON_FUNCTION = {
606606 let foundRobotMethod = false ;
607607 const robotMethods = editor . getMethodsFromRobot ( ) ;
608608 for ( const robotMethod of robotMethods ) {
609- if ( robotMethod . blockId === this . mrcOtherBlockId ) {
609+ if ( robotMethod . methodId === this . mrcOtherBlockId ) {
610610 foundRobotMethod = true ;
611611 if ( this . mrcActualFunctionName !== robotMethod . pythonName ) {
612612 this . mrcActualFunctionName = robotMethod . pythonName ;
@@ -652,7 +652,7 @@ const CALL_PYTHON_FUNCTION = {
652652 let foundMechanism = false ;
653653 const mechanismsInRobot = editor . getMechanismsFromRobot ( ) ;
654654 for ( const mechanismInRobot of mechanismsInRobot ) {
655- if ( mechanismInRobot . blockId === this . mrcMechanismBlockId ) {
655+ if ( mechanismInRobot . mechanismId === this . mrcMechanismBlockId ) {
656656 foundMechanism = true ;
657657
658658 // If the mechanism name has changed, we can handle that.
@@ -665,7 +665,7 @@ const CALL_PYTHON_FUNCTION = {
665665 const mechanismMethods : storageModuleContent . Method [ ] = mechanism
666666 ? editor . getMethodsFromMechanism ( mechanism ) : [ ] ;
667667 for ( const mechanismMethod of mechanismMethods ) {
668- if ( mechanismMethod . blockId === this . mrcOtherBlockId ) {
668+ if ( mechanismMethod . methodId === this . mrcOtherBlockId ) {
669669 foundMechanismMethod = true ;
670670 if ( this . mrcActualFunctionName !== mechanismMethod . pythonName ) {
671671 this . mrcActualFunctionName = mechanismMethod . pythonName ;
@@ -713,6 +713,17 @@ const CALL_PYTHON_FUNCTION = {
713713 this . setWarningText ( null , WARNING_ID_FUNCTION_CHANGED ) ;
714714 }
715715 } ,
716+ /**
717+ * mrcChangeIds is called when a module is copied so that the copy has different ids than the original.
718+ */
719+ mrcChangeIds : function ( this : CallPythonFunctionBlock , oldIdToNewId : { [ oldId : string ] : string } ) : void {
720+ if ( this . mrcOtherBlockId in oldIdToNewId ) {
721+ this . mrcOtherBlockId = oldIdToNewId [ this . mrcOtherBlockId ] ;
722+ }
723+ if ( this . mrcMechanismBlockId && this . mrcMechanismBlockId in oldIdToNewId ) {
724+ this . mrcMechanismBlockId = oldIdToNewId [ this . mrcMechanismBlockId ] ;
725+ }
726+ } ,
716727} ;
717728
718729export const setup = function ( ) {
@@ -868,25 +879,25 @@ function generateCodeForArguments(
868879 return code ;
869880}
870881
871- function getMethodCallers ( workspace : Blockly . Workspace , otherBlockId : string ) : Blockly . Block [ ] {
882+ function getMethodCallers ( workspace : Blockly . Workspace , id : string ) : Blockly . Block [ ] {
872883 return workspace . getBlocksByType ( BLOCK_NAME ) . filter ( ( block ) => {
873884 return (
874- ( block as CallPythonFunctionBlock ) . mrcOtherBlockId === otherBlockId ||
875- ( block as CallPythonFunctionBlock ) . mrcMechanismBlockId === otherBlockId ) ;
885+ ( block as CallPythonFunctionBlock ) . mrcOtherBlockId === id ||
886+ ( block as CallPythonFunctionBlock ) . mrcMechanismBlockId === id ) ;
876887 } ) ;
877888}
878889
879- export function renameMethodCallers ( workspace : Blockly . Workspace , otherBlockId : string , newName : string ) : void {
880- getMethodCallers ( workspace , otherBlockId ) . forEach ( block => {
881- ( block as CallPythonFunctionBlock ) . renameMethodCaller ( otherBlockId , newName ) ;
890+ export function renameMethodCallers ( workspace : Blockly . Workspace , id : string , newName : string ) : void {
891+ getMethodCallers ( workspace , id ) . forEach ( block => {
892+ ( block as CallPythonFunctionBlock ) . renameMethodCaller ( id , newName ) ;
882893 } ) ;
883894}
884895
885896export function mutateMethodCallers (
886- workspace : Blockly . Workspace , otherBlockId : string , methodOrEvent : storageModuleContent . Method | storageModuleContent . Event ) {
897+ workspace : Blockly . Workspace , id : string , methodOrEvent : storageModuleContent . Method | storageModuleContent . Event ) {
887898 const oldRecordUndo = Blockly . Events . getRecordUndo ( ) ;
888899
889- getMethodCallers ( workspace , otherBlockId ) . forEach ( block => {
900+ getMethodCallers ( workspace , id ) . forEach ( block => {
890901 const callBlock = block as CallPythonFunctionBlock ;
891902 // Get the extra state before changing the call block.
892903 const oldExtraState = callBlock . saveExtraState ( ) ;
@@ -1084,7 +1095,7 @@ function createInstanceWithinBlock(method: storageModuleContent.Method): toolbox
10841095 returnType : method . returnType ,
10851096 actualFunctionName : method . pythonName ,
10861097 args : [ ] ,
1087- otherBlockId : method . blockId ,
1098+ otherBlockId : method . methodId ,
10881099 } ;
10891100 const fields : { [ key : string ] : any } = { } ;
10901101 fields [ FIELD_FUNCTION_NAME ] = method . visibleName ;
@@ -1141,7 +1152,7 @@ function createInstanceComponentBlock(
11411152 importModule : '' ,
11421153 componentClassName : component . className ,
11431154 componentName : component . name ,
1144- otherBlockId : component . blockId ,
1155+ otherBlockId : component . componentId ,
11451156 } ;
11461157 const fields : { [ key : string ] : any } = { } ;
11471158 fields [ FIELD_COMPONENT_NAME ] = component . name ;
@@ -1169,7 +1180,7 @@ function createInstanceRobotBlock(method: storageModuleContent.Method): toolboxI
11691180 returnType : method . returnType ,
11701181 actualFunctionName : method . pythonName ,
11711182 args : [ ] ,
1172- otherBlockId : method . blockId ,
1183+ otherBlockId : method . methodId ,
11731184 } ;
11741185 const fields : { [ key : string ] : any } = { } ;
11751186 fields [ FIELD_FUNCTION_NAME ] = method . visibleName ;
@@ -1205,9 +1216,9 @@ function createInstanceMechanismBlock(
12051216 returnType : method . returnType ,
12061217 actualFunctionName : method . pythonName ,
12071218 args : [ ] ,
1208- otherBlockId : method . blockId ,
1219+ otherBlockId : method . methodId ,
12091220 mechanismClassName : mechanismInRobot . className ,
1210- mechanismBlockId : mechanismInRobot . blockId ,
1221+ mechanismBlockId : mechanismInRobot . mechanismId ,
12111222 } ;
12121223 const fields : { [ key : string ] : any } = { } ;
12131224 fields [ FIELD_MECHANISM_NAME ] = mechanismInRobot . name ;
@@ -1242,7 +1253,7 @@ function createFireEventBlock(event: storageModuleContent.Event): toolboxItems.B
12421253 functionKind : FunctionKind . EVENT ,
12431254 returnType : RETURN_TYPE_NONE ,
12441255 args : [ ] ,
1245- otherBlockId : event . blockId ,
1256+ otherBlockId : event . eventId ,
12461257 } ;
12471258 const fields : { [ key : string ] : any } = { } ;
12481259 fields [ FIELD_EVENT_NAME ] = event . name ;
0 commit comments