@@ -90,28 +90,49 @@ export const setup = function () {
9090 Blockly . Blocks [ BLOCK_NAME ] = MECHANISM_COMPONENT_HOLDER ;
9191}
9292
93- export const pythonFromBlock = function (
94- block : MechanismComponentHolderBlock ,
95- generator : ExtendedPythonGenerator ,
96- ) {
93+ function pythonFromBlockInRobot ( block : MechanismComponentHolderBlock , generator : ExtendedPythonGenerator ) {
9794 let code = 'def define_hardware(self):\n' + generator . INDENT + 'self.hardware = []\n' ;
9895
9996 let mechanisms = '' ;
10097 let components = '' ;
10198
102- if ( block . getInput ( 'MECHANISMS' ) ) {
103- mechanisms = generator . statementToCode ( block , 'MECHANISMS' ) ;
104- }
105- if ( block . getInput ( 'COMPONENTS' ) ) {
106- components = generator . statementToCode ( block , 'COMPONENTS' ) ;
107- }
99+ mechanisms = generator . statementToCode ( block , 'MECHANISMS' ) ;
100+ components = generator . statementToCode ( block , 'COMPONENTS' ) ;
101+
108102 const body = mechanisms + components ;
109103 if ( body != '' ) {
110104 code += body ;
111105 } else {
112106 code += generator . INDENT + 'pass' ;
113107 }
108+ generator . addClassMethodDefinition ( 'define_hardware' , code ) ;
109+ }
110+
111+ function pythonFromBlockInMechanism ( block : MechanismComponentHolderBlock , generator : ExtendedPythonGenerator ) {
112+ let components = '' ;
113+
114+ components = generator . statementToCode ( block , 'COMPONENTS' ) ;
114115
116+ let code = 'def define_hardware(self' + generator . getListOfPorts ( false ) + '):\n' +
117+ generator . INDENT + 'self.hardware = []\n' ;
118+
119+ if ( components != '' ) {
120+ code += components ;
121+ } else {
122+ code += generator . INDENT + 'pass' ;
123+ }
115124 generator . addClassMethodDefinition ( 'define_hardware' , code ) ;
116- return '' ;
125+ }
126+
127+ export const pythonFromBlock = function (
128+ block : MechanismComponentHolderBlock ,
129+ generator : ExtendedPythonGenerator ,
130+ ) {
131+ if ( block . getInput ( 'MECHANISMS' ) ) {
132+ pythonFromBlockInRobot ( block , generator ) ;
133+ }
134+ else {
135+ pythonFromBlockInMechanism ( block , generator ) ;
136+ }
137+ return ''
117138}
0 commit comments