@@ -16,14 +16,15 @@ function initCustomBlocksDescription() {
16
16
this . setColour ( 50 ) ;
17
17
this . appendDummyInput ( )
18
18
. appendField ( Blockly . Msg . START_TITLE )
19
- . appendField ( new Blockly . FieldImage (
20
- new Date ( ) . getMonth ( ) === 11 && CHARACTER_NAME === "Van"
21
- ? ocargo . Drawing . imageDir + "characters/top_view/Sleigh.svg"
22
- : ocargo . Drawing . imageDir + CHARACTER_EN_FACE_URL ,
23
- ocargo . BlocklyControl . BLOCK_CHARACTER_HEIGHT ,
24
- ocargo . BlocklyControl . BLOCK_CHARACTER_WIDTH
25
- )
26
- ) ;
19
+ . appendField (
20
+ new Blockly . FieldImage (
21
+ new Date ( ) . getMonth ( ) === 11 && CHARACTER_NAME === "Van"
22
+ ? ocargo . Drawing . imageDir + "characters/top_view/Sleigh.svg"
23
+ : ocargo . Drawing . imageDir + CHARACTER_EN_FACE_URL ,
24
+ ocargo . BlocklyControl . BLOCK_CHARACTER_HEIGHT ,
25
+ ocargo . BlocklyControl . BLOCK_CHARACTER_WIDTH
26
+ )
27
+ ) ;
27
28
this . setNextStatement ( true , "Action" ) ;
28
29
this . setTooltip ( Blockly . Msg . START_TOOLTIP ) ;
29
30
this . setDeletable ( false ) ;
@@ -183,22 +184,30 @@ function initCustomBlocksDescription() {
183
184
} ,
184
185
} ;
185
186
186
- Blockly . Blocks [ 'sound_horn' ] = {
187
- init : function ( ) {
188
- this . setColour ( 160 ) ;
189
- this . appendDummyInput ( )
190
- . appendField ( Blockly . Msg . SOUND_HORN_TITLE )
191
- . appendField ( new Blockly . FieldImage ( ocargo . Drawing . imageDir + 'empty.svg' ,
192
- 43 ,
193
- ocargo . BlocklyControl . BLOCK_HEIGHT ) )
194
- . appendField ( new Blockly . FieldImage ( ocargo . Drawing . imageDir + 'empty.svg' ,
195
- ocargo . BlocklyControl . IMAGE_WIDTH ,
196
- ocargo . BlocklyControl . BLOCK_HEIGHT ) ) ;
197
- this . setPreviousStatement ( true , 'Action' ) ;
198
- this . setNextStatement ( true , 'Action' ) ;
199
- this . setTooltip ( Blockly . Msg . SOUND_HORN_TOOLTIP ) ;
200
- }
201
- } ;
187
+ Blockly . Blocks [ "sound_horn" ] = {
188
+ init : function ( ) {
189
+ this . setColour ( 160 ) ;
190
+ this . appendDummyInput ( )
191
+ . appendField ( Blockly . Msg . SOUND_HORN_TITLE )
192
+ . appendField (
193
+ new Blockly . FieldImage (
194
+ ocargo . Drawing . imageDir + "empty.svg" ,
195
+ 43 ,
196
+ ocargo . BlocklyControl . BLOCK_HEIGHT
197
+ )
198
+ )
199
+ . appendField (
200
+ new Blockly . FieldImage (
201
+ ocargo . Drawing . imageDir + "empty.svg" ,
202
+ ocargo . BlocklyControl . IMAGE_WIDTH ,
203
+ ocargo . BlocklyControl . BLOCK_HEIGHT
204
+ )
205
+ ) ;
206
+ this . setPreviousStatement ( true , "Action" ) ;
207
+ this . setNextStatement ( true , "Action" ) ;
208
+ this . setTooltip ( Blockly . Msg . SOUND_HORN_TOOLTIP ) ;
209
+ } ,
210
+ } ;
202
211
203
212
/*****************/
204
213
/* Conditions */
@@ -277,33 +286,50 @@ function initCustomBlocksDescription() {
277
286
} ,
278
287
} ;
279
288
280
- Blockly . Blocks [ 'cow_crossing' ] = {
281
- init : function ( ) {
282
- this . setColour ( 210 ) ;
283
- this . setOutput ( true , 'Boolean' ) ;
284
- let imageUrl = ocargo . Drawing . animalType == ocargo . Cow . PIGEON ? ocargo . Drawing . pigeonUrl : ocargo . Drawing . whiteCowUrl
285
- this . appendDummyInput ( )
286
- . appendField ( ocargo . Drawing . animalType == ocargo . Cow . PIGEON ? Blockly . Msg . PIGEON_CROSSING_TITLE : Blockly . Msg . COW_CROSSING_TITLE )
287
- . appendField ( new Blockly . FieldImage ( ocargo . Drawing . imageDir + imageUrl ,
288
- ocargo . BlocklyControl . COW_WIDTH ,
289
- ocargo . BlocklyControl . BLOCK_HEIGHT ) , 'IMAGE' ) ;
290
- }
291
- } ;
289
+ Blockly . Blocks [ "cow_crossing" ] = {
290
+ init : function ( ) {
291
+ this . setColour ( 210 ) ;
292
+ this . setOutput ( true , "Boolean" ) ;
293
+ let imageUrl =
294
+ ocargo . Drawing . animalType == ocargo . Cow . PIGEON
295
+ ? ocargo . Drawing . pigeonUrl
296
+ : ocargo . Drawing . whiteCowUrl ;
297
+ this . appendDummyInput ( )
298
+ . appendField (
299
+ ocargo . Drawing . animalType == ocargo . Cow . PIGEON
300
+ ? Blockly . Msg . PIGEON_CROSSING_TITLE
301
+ : Blockly . Msg . COW_CROSSING_TITLE
302
+ )
303
+ . appendField (
304
+ new Blockly . FieldImage (
305
+ ocargo . Drawing . imageDir + imageUrl ,
306
+ ocargo . BlocklyControl . COW_WIDTH ,
307
+ ocargo . BlocklyControl . BLOCK_HEIGHT
308
+ ) ,
309
+ "IMAGE"
310
+ ) ;
311
+ } ,
312
+ } ;
292
313
293
- Blockly . Blocks [ 'pigeon_crossing_IMAGE_ONLY' ] = {
294
- init : function ( ) {
295
- this . setColour ( 210 ) ;
296
- this . setOutput ( true , 'Boolean' ) ;
297
- this . appendDummyInput ( )
298
- . appendField ( "pigeons" )
299
- . appendField ( new Blockly . FieldImage ( ocargo . Drawing . imageDir + ocargo . Drawing . pigeonUrl ,
300
- ocargo . BlocklyControl . COW_WIDTH ,
301
- ocargo . BlocklyControl . BLOCK_HEIGHT ) , 'IMAGE' ) ;
302
- }
303
- }
304
- /****************/
305
- /* Procedures */
306
- /****************/
314
+ Blockly . Blocks [ "pigeon_crossing_IMAGE_ONLY" ] = {
315
+ init : function ( ) {
316
+ this . setColour ( 210 ) ;
317
+ this . setOutput ( true , "Boolean" ) ;
318
+ this . appendDummyInput ( )
319
+ . appendField ( "pigeons" )
320
+ . appendField (
321
+ new Blockly . FieldImage (
322
+ ocargo . Drawing . imageDir + ocargo . Drawing . pigeonUrl ,
323
+ ocargo . BlocklyControl . COW_WIDTH ,
324
+ ocargo . BlocklyControl . BLOCK_HEIGHT
325
+ ) ,
326
+ "IMAGE"
327
+ ) ;
328
+ } ,
329
+ } ;
330
+ /****************/
331
+ /* Procedures */
332
+ /****************/
307
333
308
334
Blockly . Blocks [ "call_proc" ] = {
309
335
// Block for calling a defined procedure
@@ -559,22 +585,21 @@ function initCustomBlocksPython() {
559
585
return "my_van.wait()\n" ;
560
586
} ;
561
587
562
- Blockly . Python [ 'deliver' ] = function ( block ) {
563
- return 'my_van.deliver()\n' ;
564
- } ;
565
-
566
- Blockly . Python [ 'sound_horn' ] = function ( block ) {
567
- return 'my_van.sound_horn()\n' ;
568
- } ;
588
+ Blockly . Python [ "deliver" ] = function ( block ) {
589
+ return "my_van.deliver()\n" ;
590
+ } ;
569
591
592
+ Blockly . Python [ "sound_horn" ] = function ( block ) {
593
+ return "my_van.sound_horn()\n" ;
594
+ } ;
570
595
571
596
Blockly . Python [ "road_exists" ] = function ( block ) {
572
597
if ( block . inputList [ 0 ] . fieldRow [ 1 ] . value_ === "FORWARD" ) {
573
- var python = "my_van.is_road('FORWARD' )" ;
598
+ var python = "my_van.is_road_forward( )" ;
574
599
} else if ( block . inputList [ 0 ] . fieldRow [ 1 ] . value_ === "LEFT" ) {
575
- var python = "my_van.is_road('LEFT' )" ;
600
+ var python = "my_van.is_road_left( )" ;
576
601
} else {
577
- var python = "my_van.is_road('RIGHT' )" ;
602
+ var python = "my_van.is_road_right( )" ;
578
603
}
579
604
580
605
return [ python , Blockly . Python . ORDER_NONE ] ;
@@ -584,9 +609,9 @@ function initCustomBlocksPython() {
584
609
Blockly . Python [ "traffic_light" ] = function ( block ) {
585
610
var python ;
586
611
if ( block . inputList [ 0 ] . fieldRow [ 1 ] . value_ === ocargo . TrafficLight . RED ) {
587
- python = "my_van.at_traffic_light('RED' )" ;
612
+ python = "my_van.is_red_traffic_light( )" ;
588
613
} else {
589
- python = "my_van.at_traffic_light('GREEN' )" ;
614
+ python = "my_van.is_green_traffic_light( )" ;
590
615
}
591
616
592
617
return [ python , Blockly . Python . ORDER_NONE ] ; //TODO: figure out what this ordering relates to
@@ -628,6 +653,9 @@ function initCustomBlocksPython() {
628
653
"condition" ,
629
654
Blockly . Python . ORDER_ATOMIC
630
655
) ;
656
+
657
+ condition = condition . replace ( / \( ( .* ) \) / , "$1" ) ;
658
+
631
659
var subBlock = Blockly . Python . statementToCode ( block , "body" ) ;
632
660
var code = "while " + condition + ":\n" + subBlock ;
633
661
return code ;
0 commit comments