Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/blocks/mrc_class_method_def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const BLOCK_NAME = 'mrc_class_method_def';

export const FIELD_METHOD_NAME = 'NAME';

export type Parameter = {
type Parameter = {
name: string,
type?: string,
};
Expand Down Expand Up @@ -322,6 +322,14 @@ const CLASS_METHOD_DEF = {
this.mrcMethodId = oldIdToNewId[this.mrcMethodId];
}
},
upgrade_002_to_003: function(this: ClassMethodDefBlock) {
if (this.getFieldValue('NAME') === 'init') {
// Remove robot parameter from init method
const methodBlock = this as ClassMethodDefBlock;
let filteredParams: Parameter[] = methodBlock.mrcParameters.filter(param => param.name !== 'robot');
methodBlock.mrcParameters = filteredParams;
}
},
};

/**
Expand Down
39 changes: 16 additions & 23 deletions src/storage/upgrade_project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import * as storageModule from './module';
import * as storageModuleContent from './module_content';
import * as storageNames from './names';
import * as storageProject from './project';
import { ClassMethodDefBlock, Parameter, BLOCK_NAME as MRC_CLASS_METHOD_DEF_BLOCK_NAME } from '../blocks/mrc_class_method_def';
import { ClassMethodDefBlock, BLOCK_NAME as MRC_CLASS_METHOD_DEF_BLOCK_NAME } from '../blocks/mrc_class_method_def';

export const NO_VERSION = '0.0.0';
export const CURRENT_VERSION = '0.0.3';

export async function upgradeProjectIfNecessary(
storage: commonStorage.Storage, projectName: string): Promise<void> {
storage: commonStorage.Storage, projectName: string): Promise<void> {
const projectInfo = await storageProject.fetchProjectInfo(storage, projectName);
if (semver.lt(projectInfo.version, CURRENT_VERSION)) {
switch (projectInfo.version) {
Expand All @@ -54,18 +54,18 @@ export async function upgradeProjectIfNecessary(
}

async function upgradeFrom_000_to_001(
_storage: commonStorage.Storage,
_projectName: string,
projectInfo: storageProject.ProjectInfo): Promise<void> {
_storage: commonStorage.Storage,
_projectName: string,
projectInfo: storageProject.ProjectInfo): Promise<void> {
// Project was saved without a project.info.json file.
// Nothing needs to be done to upgrade to '0.0.1';
projectInfo.version = '0.0.1';
}

async function upgradeFrom_001_to_002(
storage: commonStorage.Storage,
projectName: string,
projectInfo: storageProject.ProjectInfo): Promise<void> {
storage: commonStorage.Storage,
projectName: string,
projectInfo: storageProject.ProjectInfo): Promise<void> {
// Modules were saved without private components.
// The Robot's mrc_mechanism_component_holder block was saved without hidePrivateComponents.
const projectFileNames: string[] = await storage.list(
Expand Down Expand Up @@ -101,9 +101,9 @@ async function upgradeFrom_001_to_002(
}

async function upgradeFrom_002_to_003(
storage: commonStorage.Storage,
projectName: string,
projectInfo: storageProject.ProjectInfo): Promise<void> {
storage: commonStorage.Storage,
projectName: string,
projectInfo: storageProject.ProjectInfo): Promise<void> {
// Opmodes had robot as a parameter to init method
const projectFileNames: string[] = await storage.list(
storageNames.makeProjectDirectoryPath(projectName));
Expand All @@ -121,17 +121,10 @@ async function upgradeFrom_002_to_003(
try {
Blockly.serialization.workspaces.load(blocks, headlessWorkspace);

// Find and modify init method blocks to remove robot parameter
const allBlocks = headlessWorkspace.getAllBlocks();
for (const block of allBlocks) {
if (block.type === MRC_CLASS_METHOD_DEF_BLOCK_NAME &&
block.getFieldValue('NAME') === 'init') {
// Remove robot parameter from init method
const methodBlock = block as ClassMethodDefBlock;
let filteredParams: Parameter[] = methodBlock.mrcParameters.filter(param => param.name !== 'robot');
methodBlock.mrcParameters = filteredParams;
}
}
// Method blocks need to be upgraded
headlessWorkspace.getBlocksByType(MRC_CLASS_METHOD_DEF_BLOCK_NAME, false).forEach(block => {
(block as ClassMethodDefBlock).upgrade_002_to_003();
});
blocks = Blockly.serialization.workspaces.save(headlessWorkspace);
} finally {
headlessWorkspace.dispose();
Expand All @@ -143,4 +136,4 @@ async function upgradeFrom_002_to_003(
}
}
projectInfo.version = '0.0.3';
}
}