Skip to content

Commit 994c206

Browse files
authored
Incremented version to 0.0.6. Added upgradeFrom_005_to_006. (#323)
In mrc_component.ts: Change the arg type from 'Port' to the real port type. In mrc_port.ts: In loadExtraState, call setOutput with the appropriate output check for the port type.
1 parent a79cbfb commit 994c206

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

src/blocks/mrc_component.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
* Copyright 2025 Porpoiseful LLC
4-
*
4+
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
@@ -192,7 +192,7 @@ const COMPONENT = {
192192
// Collect the ports for this component block.
193193
for (let i = 0; i < this.mrcArgs.length; i++) {
194194
const argName = this.getArgName(i);
195-
ports[argName] = this.mrcArgs[i].name;
195+
ports[argName] = this.mrcArgs[i].name;
196196
}
197197
},
198198
/**
@@ -247,6 +247,13 @@ const COMPONENT = {
247247
this.mrcComponentId = oldIdToNewId[this.mrcComponentId];
248248
}
249249
},
250+
upgrade_005_to_006: function(this: ComponentBlock) {
251+
for (let i = 0; i < this.mrcArgs.length; i++) {
252+
if (this.mrcArgs[i].type === 'Port') {
253+
this.mrcArgs[i].type = this.mrcArgs[i].name;
254+
}
255+
}
256+
},
250257
};
251258

252259
export const setup = function () {
@@ -318,11 +325,21 @@ function createComponentBlock(
318325
if (constructorData.expectedPortType) {
319326
extraState.params!.push({
320327
name: constructorData.expectedPortType,
321-
type: 'Port',
328+
type: constructorData.expectedPortType,
322329
});
323-
if ( moduleType == storageModule.ModuleType.ROBOT ) {
330+
if (moduleType == storageModule.ModuleType.ROBOT ) {
324331
inputs['ARG0'] = createPort(constructorData.expectedPortType);
325332
}
326333
}
327334
return new toolboxItems.Block(BLOCK_NAME, extraState, fields, Object.keys(inputs).length ? inputs : null);
328335
}
336+
337+
/**
338+
* Upgrades the ComponentBlocks in the given workspace from version 005 to 006.
339+
* This function should only be called when upgrading old projects.
340+
*/
341+
export function upgrade_005_to_006(workspace: Blockly.Workspace): void {
342+
workspace.getBlocksByType(BLOCK_NAME).forEach(block => {
343+
(block as ComponentBlock).upgrade_005_to_006();
344+
});
345+
}

src/blocks/mrc_port.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
* Copyright 2025 Porpoiseful LLC
4-
*
4+
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
@@ -26,6 +26,7 @@ import { MRC_STYLE_PORTS } from '../themes/styles'
2626
import { createFieldNonEditableText } from '../fields/FieldNonEditableText';
2727
import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2828
import { createFieldNumberDropdown } from '../fields/field_number_dropdown';
29+
import { getOutputCheck } from './utils/python';
2930

3031
export const BLOCK_NAME = 'mrc_port';
3132
export const OUTPUT_NAME = 'mrc_port';
@@ -119,6 +120,7 @@ const PORT = {
119120
}
120121
this.mrcPortType = state.portType;
121122
this.mrcPortCount = iField;
123+
this.setOutput(true, getOutputCheck(this.mrcPortType));
122124
},
123125
}
124126

src/storage/upgrade_project.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import * as storageNames from './names';
2929
import * as storageProject from './project';
3030
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';
32+
import { upgrade_005_to_006 } from '../blocks/mrc_component';
3233
import * as workspaces from '../blocks/utils/workspaces';
3334

3435
export const NO_VERSION = '0.0.0';
35-
export const CURRENT_VERSION = '0.0.5';
36+
export const CURRENT_VERSION = '0.0.6';
3637

3738
export async function upgradeProjectIfNecessary(
3839
storage: commonStorage.Storage, projectName: string): Promise<void> {
@@ -66,6 +67,11 @@ export async function upgradeProjectIfNecessary(
6667
// @ts-ignore
6768
case '0.0.4':
6869
upgradeFrom_004_to_005(storage, projectName, projectInfo);
70+
71+
// Intentional fallthrough after case '0.0.5'
72+
// @ts-ignore
73+
case '0.0.5':
74+
upgradeFrom_005_to_006(storage, projectName, projectInfo);
6975
}
7076
await storageProject.saveProjectInfo(storage, projectName);
7177
}
@@ -212,3 +218,15 @@ async function upgradeFrom_004_to_005(
212218
anyModuleType, upgrade_004_to_005);
213219
projectInfo.version = '0.0.5';
214220
}
221+
222+
async function upgradeFrom_005_to_006(
223+
storage: commonStorage.Storage,
224+
projectName: string,
225+
projectInfo: storageProject.ProjectInfo): Promise<void> {
226+
// mrc_component blocks parameter types need to be fixed.
227+
await upgradeBlocksFiles(
228+
storage, projectName,
229+
noModuleTypes, noPreupgrade,
230+
anyModuleType, upgrade_005_to_006);
231+
projectInfo.version = '0.0.6';
232+
}

0 commit comments

Comments
 (0)