Skip to content

Commit f922325

Browse files
committed
Fixed where holder had to be before init to generate correctly
1 parent 35eb4dd commit f922325

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/blocks/mrc_mechanism_component_holder.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,10 @@ export const pythonFromBlock = function (
219219
block: MechanismComponentHolderBlock,
220220
generator: ExtendedPythonGenerator,
221221
) {
222-
generator.setHasHardware();
223222
let code = 'def define_hardware(self):\n';
224223

225224
let body = '';
226-
for(let i = 1; i <= this.mrcNumMechanismInputs; i++){
225+
for(let i = 1; i <= block.mrcNumMechanismInputs; i++){
227226
const name = 'MECHANISM_' + i;
228227
if(block.getInput(name)){
229228
let mechanismCode = generator.valueToCode(block, name, Order.NONE) || '';
@@ -232,7 +231,7 @@ export const pythonFromBlock = function (
232231
}
233232
}
234233
}
235-
for(let i = 1; i <= this.mrcNumComponentInputs; i++){
234+
for(let i = 1; i <= block.mrcNumComponentInputs; i++){
236235
const name = 'COMPONENT_' + i;
237236
if(block.getInput(name)){
238237
let componentCode = generator.valueToCode(block, name, Order.NONE) || '';

src/editor/extended_python_generator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import * as Blockly from 'blockly/core';
2323
import { PythonGenerator } from 'blockly/python';
2424
import { GeneratorContext } from './generator_context';
2525
import { Block } from '../toolbox/items';
26-
import { CallPythonFunctionBlock, FunctionArg } from '../blocks/mrc_call_python_function';
26+
import { FunctionArg } from '../blocks/mrc_call_python_function';
27+
import * as MechanismContainerHolder from '../blocks/mrc_mechanism_component_holder';
2728
import * as commonStorage from '../storage/common_storage';
2829

2930
// Extends the python generator to collect some information about functions and
@@ -82,6 +83,10 @@ export class ExtendedPythonGenerator extends PythonGenerator {
8283
this.context = context;
8384
this.context.clear();
8485

86+
if (this.workspace.getBlocksByType(MechanismContainerHolder.BLOCK_NAME).length > 0){
87+
this.setHasHardware();
88+
}
89+
8590
const code = super.workspaceToCode(workspace);
8691

8792
this.workspace = workspace;

0 commit comments

Comments
 (0)