@@ -27,6 +27,8 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
2727import { createStepFieldFlydown } from '../fields/field_flydown' ;
2828import { BLOCK_NAME as MRC_JUMP_TO_STEP } from './mrc_jump_to_step' ;
2929import * as stepContainer from './mrc_step_container'
30+ import * as value from './utils/value' ;
31+ import * as toolboxItems from '../toolbox/items' ;
3032
3133export const BLOCK_NAME = 'mrc_steps' ;
3234
@@ -49,7 +51,7 @@ const STEPS = {
4951 * Block initialization.
5052 */
5153 init : function ( this : StepsBlock ) : void {
52- this . mrcStepNames = [ "0" ] ;
54+ this . mrcStepNames = [ ] ;
5355 this . appendDummyInput ( )
5456 . appendField ( Blockly . Msg . STEPS ) ;
5557 this . setInputsInline ( false ) ;
@@ -63,10 +65,8 @@ const STEPS = {
6365 } ;
6466 } ,
6567 loadExtraState : function ( this : StepsBlock , state : StepsExtraState ) : void {
66- if ( state && state . stepNames ) {
67- this . mrcStepNames = state . stepNames ;
68- this . updateShape_ ( ) ;
69- }
68+ this . mrcStepNames = state . stepNames ;
69+ this . updateShape_ ( ) ;
7070 } ,
7171 compose : function ( this : StepsBlock , containerBlock : Blockly . Block ) {
7272 if ( containerBlock . type !== stepContainer . STEP_CONTAINER_BLOCK_NAME ) {
@@ -171,8 +171,12 @@ const STEPS = {
171171 const stepConnection = this . getInput ( 'STEP_' + currentIndex ) ?. connection ?. targetConnection ;
172172
173173 // Temporarily disconnect
174- if ( conditionConnection ) conditionConnection . disconnect ( ) ;
175- if ( stepConnection ) stepConnection . disconnect ( ) ;
174+ if ( conditionConnection ) {
175+ conditionConnection . disconnect ( ) ;
176+ }
177+ if ( stepConnection ) {
178+ stepConnection . disconnect ( ) ;
179+ }
176180
177181 // Remove old inputs
178182 this . removeInput ( 'CONDITION_' + currentIndex , false ) ;
@@ -256,7 +260,7 @@ export const pythonFromBlock = function (
256260 generator : ExtendedPythonGenerator ,
257261) {
258262 let code = 'def steps(self):\n' ;
259- code += generator . INDENT + 'if not self. _initialized_steps:\n' ;
263+ code += generator . INDENT + 'if not hasattr( self, " _initialized_steps") :\n' ;
260264 code += generator . INDENT . repeat ( 2 ) + 'self._current_step = "' + block . mrcStepNames [ 0 ] + '"\n' ;
261265 code += generator . INDENT . repeat ( 2 ) + 'self._initialized_steps = True\n\n' ;
262266 code += generator . INDENT + 'if self._current_step == None:\n' ;
@@ -282,4 +286,14 @@ export const pythonFromBlock = function (
282286 generator . addClassMethodDefinition ( 'steps' , code ) ;
283287
284288 return ''
285- }
289+ }
290+
291+ export function createStepsBlock ( ) : toolboxItems . Block {
292+ const extraState : StepsExtraState = {
293+ stepNames : [ '0' ] ,
294+ } ;
295+ const fields : { [ key : string ] : any } = { } ;
296+ const inputs : { [ key : string ] : any } = { } ;
297+ inputs [ 'CONDITION_' + 0 ] = value . createBooleanShadowValue ( true ) ;
298+ return new toolboxItems . Block ( BLOCK_NAME , extraState , fields , inputs ) ;
299+ }
0 commit comments