Skip to content

Commit a40bc55

Browse files
committed
Use expected port type
1 parent 9eda6cc commit a40bc55

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/blocks/mrc_component.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,10 @@ export function getAllPossibleComponents(
229229
throw new Error('Could not find classData for ' + componentType);
230230
}
231231

232-
const componentName = (
233-
'my_' +
234-
storageNames.pascalCaseToSnakeCase(
235-
componentType.substring(componentType.lastIndexOf('.') + 1)));
232+
const componentName = 'my_' + classData.moduleName;
236233

237-
classData.staticMethods.forEach(staticFunctionData => {
238-
if (staticFunctionData.returnType === componentType) {
239-
contents.push(createComponentBlock(componentName, classData, staticFunctionData, moduleType));
240-
}
234+
classData.constructors.forEach(constructor => {
235+
contents.push(createComponentBlock(componentName, classData, constructor, moduleType));
241236
});
242237
});
243238

@@ -247,32 +242,27 @@ export function getAllPossibleComponents(
247242
function createComponentBlock(
248243
componentName: string,
249244
classData: ClassData,
250-
staticFunctionData: FunctionData,
245+
constructorData: FunctionData,
251246
moduleType: storageModule.ModuleType): toolboxItems.Block {
252247
const extraState: ComponentExtraState = {
253248
importModule: classData.moduleName,
254-
staticFunctionName: staticFunctionData.functionName,
249+
//TODO(ags): Remove this because we know what the constructor name is
250+
staticFunctionName: constructorData.functionName,
255251
params: [],
256252
};
257253
const fields: {[key: string]: any} = {};
258254
fields[FIELD_NAME] = componentName;
259255
fields[FIELD_TYPE] = classData.className;
260256
const inputs: {[key: string]: any} = {};
261-
for (let i = 0; i < staticFunctionData.args.length; i++) {
262-
const argData = staticFunctionData.args[i];
257+
258+
if (constructorData.expectedPortType) {
263259
extraState.params!.push({
264-
'name': argData.name,
265-
'type': argData.type,
260+
//TODO(Alan): Make this a localized version of the port type
261+
'name': constructorData.expectedPortType,
262+
'type': 'Port',
266263
});
267-
if (moduleType == storageModule.ModuleType.ROBOT) {
268-
if (argData.type === 'int') {
269-
const portType = getPortTypeForArgument(argData.name);
270-
if (portType) {
271-
inputs['ARG' + i] = createPortShadow(portType);
272-
} else {
273-
inputs['ARG' + i] = createNumberShadowValue(1);
274-
}
275-
}
264+
if ( moduleType == storageModule.ModuleType.ROBOT ) {
265+
inputs['ARG0'] = createPortShadow(constructorData.expectedPortType);
276266
}
277267
}
278268
return new toolboxItems.Block(BLOCK_NAME, extraState, fields, Object.keys(inputs).length ? inputs : null);

0 commit comments

Comments
 (0)