Skip to content

Commit 84df4d3

Browse files
committed
In mrc_mechanism_component_holder.ts:
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.
1 parent ec1377b commit 84df4d3

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/blocks/mrc_mechanism_component_holder.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { ComponentBlock } from './mrc_component';
3636
import { BLOCK_NAME as MRC_EVENT_NAME } from './mrc_event';
3737
import { OUTPUT_NAME as EVENT_OUTPUT } from './mrc_event';
3838
import { EventBlock } from './mrc_event';
39+
import { getModuleTypeForWorkspace } from './utils/workspaces';
3940

4041
export const BLOCK_NAME = 'mrc_mechanism_component_holder';
4142

@@ -520,13 +521,18 @@ export function mrcDescendantsMayHaveChanged(workspace: Blockly.Workspace): void
520521
}
521522

522523
/**
523-
* Hide private components.
524+
* Upgrades the MechanismComponentHolderBlock in the given workspace from version 001 to 002 by
525+
* setting mrcHidePrivateComponents to true.
524526
* This function should only be called when upgrading old projects.
525527
*/
526-
export function hidePrivateComponents(workspace: Blockly.Workspace) {
528+
export function upgrade_001_to_002(workspace: Blockly.Workspace) {
527529
// Make sure the workspace is headless.
528530
if (workspace.rendered) {
529-
throw new Error('hidePrivateComponents should never be called with a rendered workspace.');
531+
throw new Error('upgrade_001_to_002 should never be called with a rendered workspace.');
532+
}
533+
// Make sure the module type is ROBOT.
534+
if (getModuleTypeForWorkspace(workspace) !== storageModule.ModuleType.ROBOT) {
535+
throw new Error('upgrade_001_to_002 should only be called for a robot module.');
530536
}
531537
workspace.getBlocksByType(BLOCK_NAME).forEach(block => {
532538
(block as MechanismComponentHolderBlock).mrcHidePrivateComponents = true;

src/storage/module_content.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ export class ModuleContent {
270270
}
271271

272272
/**
273-
* Add privateComponents field.
274-
* This function should only called when upgrading old projects.
273+
* Preupgrades the module content text by adding the privateComponents field.
274+
* This function should only be called when upgrading old projects.
275275
*/
276-
export function addPrivateComponents(moduleContentText: string): string {
276+
export function preupgrade_001_to_002(moduleContentText: string): string {
277277
const parsedContent = JSON.parse(moduleContentText);
278278
if (!('privateComponents' in parsedContent)) {
279279
parsedContent.privateComponents = [];

src/storage/upgrade_project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import * as semver from 'semver';
2323
import * as Blockly from 'blockly/core';
2424

25-
import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder';
2625
import * as commonStorage from './common_storage';
2726
import * as storageModule from './module';
2827
import * as storageModuleContent from './module_content';
2928
import * as storageNames from './names';
3029
import * as storageProject from './project';
30+
import { upgrade_001_to_002 } from '../blocks/mrc_mechanism_component_holder';
3131
import { upgrade_002_to_003, upgrade_004_to_005 } from '../blocks/mrc_class_method_def';
3232
import * as workspaces from '../blocks/utils/workspaces';
3333

@@ -172,8 +172,8 @@ async function upgradeFrom_001_to_002(
172172
// The Robot's mrc_mechanism_component_holder block was saved without hidePrivateComponents.
173173
await upgradeBlocksFiles(
174174
storage, projectName,
175-
anyModuleType, storageModuleContent.addPrivateComponents,
176-
isRobot, mechanismComponentHolder.hidePrivateComponents);
175+
anyModuleType, storageModuleContent.preupgrade_001_to_002,
176+
isRobot, upgrade_001_to_002);
177177
projectInfo.version = '0.0.2';
178178
}
179179

0 commit comments

Comments
 (0)