Skip to content

Conversation

@lizlooney
Copy link
Collaborator

@lizlooney lizlooney commented Nov 7, 2025

Fixed mrc_class_method_def blocks for methods that return a value.

Also, refactored upgrade functions: I added a new function named upgradeBlocksFiles that takes predicate functions that control what files should be upgraded and functions to do the upgrading. I updated the upgradeFrom_00*_to_00* functions to call upgradeBlocksFiles.

Fixes #296.
Fixes #238.

Added constants for NO_RETURN_VALUE and UNTYPED_RETURN_VALUE.
Added upgrade_004_to_005 to change mrcReturnType from 'Any' to UNTYPED_RETURN_VALUE.
Changed createCustomMethodBlockWithReturn to use UNTYPED_RETURN_VALUE instead of 'Any'.

In upgrade_project.ts:
Incremented CURRENT_VERSION to 0.0.5.
Changed switch statement in upgradeProjectIfNecessary to have the default case at the top.
All other cases have @ts-ignore and blank lines so it is more clear that the @ts-ignore goes with the case after it.
Added upgradeBlocksFiles function that can be called from other upgradeFrom_..._to_... functions.
Added upgradeFrom_004_to_005.
Added upgrade_002_to_003 function.

In upgrade_project.ts:
Modified upgradeBlocksFiles to take a predicate function.
Added anyModuleType and isOpMode functions that can be passed to upgradeBlocksFiles as the predicate function.
Modified upgradeFrom_002_to_003 to call upgradeBlocksFiles.
Modified upgradeFrom_004_to_005 to pass anyModuleType to upgradeBlocksFiles.
…cksFiles.

Modified upgradeFrom_001_to_002 to call upgradeBlocksFiles.
Renamed function hidePrivateComponents to upgrade_001_to_002 and added code to check that the module type is ROBOT.

In module_content.ts:
Renamed addPrivateComponents to preupgrade_001_to_002.

In upgrade_project.ts:
Updated upgradeFrom_001_to_002.
@lizlooney lizlooney requested a review from alan412 November 7, 2025 07:46
Copy link
Collaborator

@alan412 alan412 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work when there are multiple blocks that need to be upgraded? Do you just create a method here that calls each one and then pass it in?

*/
export function upgrade_002_to_003(workspace: Blockly.Workspace): void {
// Make sure the workspace is headless.
if (workspace.rendered) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we pull these out and check it in the upgrade project so it doesn't have to be littered throughout the code?

Copy link
Collaborator Author

@lizlooney lizlooney Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of checking it here is to make sure this function is not called from code other than the upgrade code. But, since these functions all have names upgrade_*_to_*, I guess it is not necessary.

@lizlooney
Copy link
Collaborator Author

How does this work when there are multiple blocks that need to be upgraded? Do you just create a method here that calls each one and then pass it in?

Yes, I'd just create a lambda function that calls the other two functions:

const upgradeFunc = (workspace: Blockly.Workspace) => {
  mechanismComponentHolder.upgrade_008_to_009(workspace);
  classMethodDef.upgrade_008_to_009(workspace);
};

If the upgrade is more complicated, using upgradeBlocksFiles may not be possible, but it works for the cases we have so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block that calls a user defined method won't snap into a socket that expects a boolean or number Changes to upgrade logic...

2 participants