File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -118,17 +118,16 @@ export const setup = function () {
118118 Blockly . Blocks [ BLOCK_NAME ] = MECHANISM_FUNCTION ;
119119}
120120
121- //TODO: This needs to cause our own init to create the mechanisms line
122121export const pythonFromBlock = function (
123122 mechanismBlock : MechanismBlock ,
124123 generator : ExtendedPythonGenerator ,
125124) {
126125 if ( mechanismBlock . mrcImportModule ) {
127126 generator . addImport ( mechanismBlock . mrcImportModule ) ;
128127 }
128+ generator . setHasMechanism ( ) ;
129129 let code = 'self.mechanisms["' + mechanismBlock . getFieldValue ( 'NAME' ) + '"] = '
130130 + mechanismBlock . getFieldValue ( 'TYPE' ) + '('
131-
132131 for ( let i = 0 ; i < mechanismBlock . mrcArgs . length ; i ++ ) {
133132 const fieldName = 'ARG' + i ;
134133 if ( i != 0 ) {
Original file line number Diff line number Diff line change @@ -64,13 +64,19 @@ export class ExtendedPythonGenerator extends PythonGenerator {
6464 for ( let i = 0 ; i < classVars . length ; i ++ ) {
6565 variableDefinitions += this . INDENT + this . getVariableName ( classVars [ i ] . getId ( ) ) + ' = None\n' ;
6666 }
67+ if ( this . context ?. getHasMechanisms ( ) ) {
68+ variableDefinitions += this . INDENT + "self.mechanisms = []\n" ;
69+ }
6770 return variableDefinitions ;
6871 }
6972 getVariableName ( name : string ) : string {
7073 const varName = super . getVariableName ( name ) ;
7174 return "self." + varName ;
7275 }
73-
76+ setHasMechanism ( ) : void {
77+ this . context ?. setHasMechanism ( ) ;
78+ }
79+
7480 workspaceToCode ( workspace : Blockly . Workspace , context : GeneratorContext ) : string {
7581 this . workspace = workspace ;
7682 this . context = context ;
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ export class GeneratorContext {
3636 // Key is the mrc_class_method_def block's NAME field, value is the python method name.
3737 private classMethodNames : { [ key : string ] : string } = Object . create ( null ) ;
3838
39+ // Has mechanisms (ie, needs in init)
40+ private hasMechanisms = false ;
41+
3942 setModule ( module : commonStorage . Module | null ) {
4043 this . module = module ;
4144 this . clear ( ) ;
@@ -44,6 +47,13 @@ export class GeneratorContext {
4447 clear ( ) : void {
4548 this . clearExportedBlocks ( ) ;
4649 this . clearClassMethodNames ( ) ;
50+ this . hasMechanisms = false ;
51+ }
52+ setHasMechanism ( ) :void {
53+ this . hasMechanisms = true ;
54+ }
55+ getHasMechanisms ( ) :boolean {
56+ return this . hasMechanisms ;
4757 }
4858
4959 getClassName ( ) : string {
You can’t perform that action at this time.
0 commit comments