@@ -27,6 +27,8 @@ import * as eventHandler from '../blocks/mrc_event_handler';
2727import {
2828 MODULE_NAME_BLOCKS_BASE_CLASSES ,
2929 CLASS_NAME_OPMODE ,
30+ PERIODIC_METHOD_NAME ,
31+ STEPS_METHOD_NAME ,
3032 getClassData ,
3133} from '../blocks/utils/python' ;
3234import * as storageModule from '../storage/module' ;
@@ -248,6 +250,22 @@ export class ExtendedPythonGenerator extends PythonGenerator {
248250
249251 code = decorators + 'class ' + className + '(' + baseClassName + '):\n' ;
250252
253+ if ( this . getModuleType ( ) === storageModule . ModuleType . OPMODE ) {
254+ // If the user has a steps method, we need to generate code to call it from the periodic method.
255+ if ( STEPS_METHOD_NAME in this . classMethods ) {
256+ let periodicCode : string ;
257+ if ( PERIODIC_METHOD_NAME in this . classMethods ) {
258+ periodicCode = this . classMethods [ PERIODIC_METHOD_NAME ] ;
259+ } else {
260+ periodicCode = `def {PERIODIC_METHOD_NAME}():\n` ;
261+ periodicCode += this . INDENT + `super().{PERIODIC_METHOD_NAME}()\n` ;
262+ }
263+ periodicCode += this . INDENT + `if hasattr(self, '${ STEPS_METHOD_NAME } ') and callable(self.${ STEPS_METHOD_NAME } ):\n` ;
264+ periodicCode += this . INDENT . repeat ( 2 ) + `self.${ STEPS_METHOD_NAME } ()\n` ;
265+ this . classMethods [ PERIODIC_METHOD_NAME ] = periodicCode ;
266+ }
267+ }
268+
251269 const classMethods = [ ] ;
252270
253271 // Generate the __init__ method first.
@@ -295,7 +313,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {
295313 this . opModeDetails = opModeDetails ;
296314 }
297315
298- getClassSpecificForInit ( ) : string {
316+ getSuperInitParameters ( ) : string {
299317 if ( this . context ?. getBaseClassName ( ) == CLASS_NAME_OPMODE ) {
300318 return 'robot'
301319 }
0 commit comments