@@ -32,6 +32,9 @@ import * as toolboxItems from '../toolbox/items';
3232
3333export const BLOCK_NAME = 'mrc_steps' ;
3434
35+ const INPUT_CONDITION_PREFIX = 'CONDITION_' ;
36+ const INPUT_STEP_PREFIX = 'STEP_' ;
37+
3538/** Extra state for serialising mrc_steps blocks. */
3639type StepsExtraState = {
3740 /**
@@ -151,8 +154,8 @@ const STEPS = {
151154 // Build a map of step names to their current input indices
152155 const currentStepMap : { [ stepName : string ] : number } = { } ;
153156 let i = 0 ;
154- while ( this . getInput ( 'CONDITION_' + i ) ) {
155- const conditionInput = this . getInput ( 'CONDITION_' + i ) ;
157+ while ( this . getInput ( INPUT_CONDITION_PREFIX + i ) ) {
158+ const conditionInput = this . getInput ( INPUT_CONDITION_PREFIX + i ) ;
156159 const field = conditionInput ?. fieldRow [ 0 ] ;
157160 if ( field ) {
158161 currentStepMap [ field . getValue ( ) ] = i ;
@@ -167,8 +170,8 @@ const STEPS = {
167170
168171 if ( currentIndex !== undefined && currentIndex !== j ) {
169172 // Step exists but is at wrong position - move it
170- const conditionConnection = this . getInput ( 'CONDITION_' + currentIndex ) ?. connection ?. targetConnection ;
171- const stepConnection = this . getInput ( 'STEP_' + currentIndex ) ?. connection ?. targetConnection ;
173+ const conditionConnection = this . getInput ( INPUT_CONDITION_PREFIX + currentIndex ) ?. connection ?. targetConnection ;
174+ const stepConnection = this . getInput ( INPUT_STEP_PREFIX + currentIndex ) ?. connection ?. targetConnection ;
172175
173176 // Temporarily disconnect
174177 if ( conditionConnection ) {
@@ -179,31 +182,31 @@ const STEPS = {
179182 }
180183
181184 // Remove old inputs
182- this . removeInput ( 'CONDITION_' + currentIndex , false ) ;
183- this . removeInput ( 'STEP_' + currentIndex , false ) ;
185+ this . removeInput ( INPUT_CONDITION_PREFIX + currentIndex , false ) ;
186+ this . removeInput ( INPUT_STEP_PREFIX + currentIndex , false ) ;
184187
185188 // Create new inputs at correct position
186189 const fieldFlydown = createStepFieldFlydown ( stepName , true ) ;
187190 fieldFlydown . setValidator ( this . mrcUpdateStepName . bind ( this , j ) ) ;
188191
189- this . appendValueInput ( 'CONDITION_' + j )
192+ this . appendValueInput ( INPUT_CONDITION_PREFIX + j )
190193 . appendField ( fieldFlydown )
191194 . setCheck ( 'Boolean' )
192195 . appendField ( Blockly . Msg . REPEAT_UNTIL ) ;
193- this . appendStatementInput ( 'STEP_' + j ) ;
196+ this . appendStatementInput ( INPUT_STEP_PREFIX + j ) ;
194197
195198 // Reconnect
196199 if ( conditionConnection ) {
197- this . getInput ( 'CONDITION_' + j ) ?. connection ?. connect ( conditionConnection ) ;
200+ this . getInput ( INPUT_CONDITION_PREFIX + j ) ?. connection ?. connect ( conditionConnection ) ;
198201 }
199202 if ( stepConnection ) {
200- this . getInput ( 'STEP_' + j ) ?. connection ?. connect ( stepConnection ) ;
203+ this . getInput ( INPUT_STEP_PREFIX + j ) ?. connection ?. connect ( stepConnection ) ;
201204 }
202205
203206 delete currentStepMap [ stepName ] ;
204207 } else if ( currentIndex !== undefined ) {
205208 // Step is at correct position - just update the field
206- const conditionInput = this . getInput ( 'CONDITION_' + j ) ;
209+ const conditionInput = this . getInput ( INPUT_CONDITION_PREFIX + j ) ;
207210 const field = conditionInput ?. fieldRow [ 0 ] ;
208211 if ( field && field . getValue ( ) !== stepName ) {
209212 field . setValue ( stepName ) ;
@@ -214,11 +217,11 @@ const STEPS = {
214217 const fieldFlydown = createStepFieldFlydown ( stepName , true ) ;
215218 fieldFlydown . setValidator ( this . mrcUpdateStepName . bind ( this , j ) ) ;
216219
217- const conditionInput = this . appendValueInput ( 'CONDITION_' + j )
220+ const conditionInput = this . appendValueInput ( INPUT_CONDITION_PREFIX + j )
218221 . appendField ( fieldFlydown )
219222 . setCheck ( 'Boolean' )
220223 . appendField ( Blockly . Msg . REPEAT_UNTIL ) ;
221- this . appendStatementInput ( 'STEP_' + j ) ;
224+ this . appendStatementInput ( INPUT_STEP_PREFIX + j ) ;
222225
223226 // Add shadow True block to the new condition input
224227 if ( this . workspace ) {
@@ -237,8 +240,8 @@ const STEPS = {
237240 // Remove any leftover inputs (steps that were deleted)
238241 for ( const stepName in currentStepMap ) {
239242 const index = currentStepMap [ stepName ] ;
240- this . removeInput ( 'CONDITION_' + index , false ) ;
241- this . removeInput ( 'STEP_' + index , false ) ;
243+ this . removeInput ( INPUT_CONDITION_PREFIX + index , false ) ;
244+ this . removeInput ( INPUT_STEP_PREFIX + index , false ) ;
242245 }
243246 } ,
244247 mrcGetStepNames : function ( this : StepsBlock ) : string [ ] {
@@ -270,11 +273,11 @@ export const pythonFromBlock = function (
270273 code += generator . INDENT + 'match self._current_step:\n' ;
271274 block . mrcStepNames . forEach ( ( stepName , index ) => {
272275 code += generator . INDENT . repeat ( 2 ) + `case "${ stepName } ":\n` ;
273- let stepCode = generator . statementToCode ( block , 'STEP_' + index ) ;
276+ let stepCode = generator . statementToCode ( block , INPUT_STEP_PREFIX + index ) ;
274277 if ( stepCode !== '' ) {
275278 code += generator . prefixLines ( stepCode , generator . INDENT . repeat ( 2 ) ) ;
276279 }
277- let conditionCode = generator . valueToCode ( block , 'CONDITION_' + index , Order . NONE ) || 'False' ;
280+ let conditionCode = generator . valueToCode ( block , INPUT_CONDITION_PREFIX + index , Order . NONE ) || 'False' ;
278281 code += generator . INDENT . repeat ( 3 ) + 'if ' + conditionCode + ':\n' ;
279282 if ( index === block . mrcStepNames . length - 1 ) {
280283 code += generator . INDENT . repeat ( 4 ) + 'self._current_step = None\n' ;
@@ -294,6 +297,6 @@ export function createStepsBlock(): toolboxItems.Block {
294297 } ;
295298 const fields : { [ key : string ] : any } = { } ;
296299 const inputs : { [ key : string ] : any } = { } ;
297- inputs [ 'CONDITION_' + 0 ] = value . createBooleanShadowValue ( true ) ;
300+ inputs [ INPUT_CONDITION_PREFIX + 0 ] = value . createBooleanShadowValue ( true ) ;
298301 return new toolboxItems . Block ( BLOCK_NAME , extraState , fields , inputs ) ;
299302}
0 commit comments