@@ -362,6 +362,7 @@ static func get_general_blocks() -> Array[Block]:
362
362
b .variant_type = TYPE_VECTOR2
363
363
b .block_format = "Vector2 x: {x: FLOAT} y: {y: FLOAT} "
364
364
b .statement = "Vector2({x} , {y} )"
365
+ b .defaults = {"x" : "0" , "y" : "0" }
365
366
b .category = "Variables"
366
367
block_list .append (b )
367
368
@@ -373,6 +374,7 @@ static func get_general_blocks() -> Array[Block]:
373
374
b .variant_type = TYPE_INT
374
375
b .block_format = "{a: INT} + {b: INT} "
375
376
b .statement = "({a} + {b} )"
377
+ b .defaults = {"a" : "1" , "b" : "1" }
376
378
b .category = "Math"
377
379
block_list .append (b )
378
380
@@ -381,6 +383,7 @@ static func get_general_blocks() -> Array[Block]:
381
383
b .variant_type = TYPE_INT
382
384
b .block_format = "{a: INT} - {b: INT} "
383
385
b .statement = "({a} - {b} )"
386
+ b .defaults = {"a" : "1" , "b" : "1" }
384
387
b .category = "Math"
385
388
block_list .append (b )
386
389
@@ -389,6 +392,7 @@ static func get_general_blocks() -> Array[Block]:
389
392
b .variant_type = TYPE_INT
390
393
b .block_format = "{a: INT} * {b: INT} "
391
394
b .statement = "({a} * {b} )"
395
+ b .defaults = {"a" : "1" , "b" : "1" }
392
396
b .category = "Math"
393
397
block_list .append (b )
394
398
@@ -397,6 +401,7 @@ static func get_general_blocks() -> Array[Block]:
397
401
b .variant_type = TYPE_INT
398
402
b .block_format = "{a: INT} / {b: INT} "
399
403
b .statement = "({a} / {b} )"
404
+ b .defaults = {"a" : "1" , "b" : "1" }
400
405
b .category = "Math"
401
406
block_list .append (b )
402
407
@@ -405,6 +410,7 @@ static func get_general_blocks() -> Array[Block]:
405
410
b .variant_type = TYPE_INT
406
411
b .block_format = "{base: INT} ^ {exp: INT} "
407
412
b .statement = "(pow({base} , {exp} ))"
413
+ b .defaults = {"base" : "1" , "exp" : "1" }
408
414
b .category = "Math"
409
415
block_list .append (b )
410
416
@@ -413,14 +419,14 @@ static func get_general_blocks() -> Array[Block]:
413
419
414
420
b = BLOCKS ["control_block" ].instantiate ()
415
421
b .block_name = "if"
416
- b .block_formats = ["if {condition: BOOL} " ]
422
+ b .block_formats = ["if {condition: BOOL} " ]
417
423
b .statements = ["if {condition} :" ]
418
424
b .category = "Logic | Conditionals"
419
425
block_list .append (b )
420
426
421
427
b = BLOCKS ["control_block" ].instantiate ()
422
428
b .block_name = "if_else"
423
- b .block_formats = ["if {condition: BOOL} " , "else" ]
429
+ b .block_formats = ["if {condition: BOOL} " , "else" ]
424
430
b .statements = ["if {condition} :" , "else:" ]
425
431
b .category = "Logic | Conditionals"
426
432
block_list .append (b )
@@ -430,7 +436,11 @@ static func get_general_blocks() -> Array[Block]:
430
436
b .variant_type = TYPE_BOOL
431
437
b .block_format = "{int1: INT} {op: OPTION} {int2: INT} "
432
438
b .statement = "({int1} {op} {int2} )"
433
- b .defaults = {"op" : OptionData .new (["==" , ">" , "<" , ">=" , "<=" , "!=" ])}
439
+ b .defaults = {
440
+ "op" : OptionData .new (["==" , ">" , "<" , ">=" , "<=" , "!=" ]),
441
+ "int1" : "1" ,
442
+ "int2" : "1" ,
443
+ }
434
444
b .category = "Logic | Comparison"
435
445
block_list .append (b )
436
446
@@ -529,22 +539,41 @@ static func property_to_blocklist(property: Dictionary) -> Array[Block]:
529
539
530
540
var variant_type = property .type
531
541
542
+ const FALLBACK_SET_FOR_TYPE = {
543
+ TYPE_INT : "0" ,
544
+ TYPE_FLOAT : "0" ,
545
+ TYPE_VECTOR2 : "0, 0" ,
546
+ TYPE_COLOR : "DARK_ORANGE" ,
547
+ }
548
+
549
+ const FALLBACK_CHANGE_FOR_TYPE = {
550
+ TYPE_INT : "1" ,
551
+ TYPE_FLOAT : "1" ,
552
+ TYPE_VECTOR2 : "1, 1" ,
553
+ TYPE_COLOR : "DARK_ORANGE" ,
554
+ }
555
+
532
556
if variant_type :
533
557
var type_string : String = Types .VARIANT_TYPE_TO_STRING [variant_type ]
534
558
535
559
var b = BLOCKS ["statement_block" ].instantiate ()
536
560
b .block_name = "set_prop_%s " % property .name
537
561
b .block_format = "Set %s to {value: %s} " % [property .name .capitalize (), type_string ]
538
562
b .statement = "%s = {value} " % property .name
563
+ var default_set = property .get ("default_set" , FALLBACK_SET_FOR_TYPE .get (variant_type , "" ))
564
+ b .defaults = {"value" : default_set }
539
565
b .category = property .category
540
566
block_list .append (b )
541
567
542
- b = BLOCKS ["statement_block" ].instantiate ()
543
- b .block_name = "change_prop_%s " % property .name
544
- b .block_format = "Change %s by {value: %s} " % [property .name .capitalize (), type_string ]
545
- b .statement = "%s += {value} " % property .name
546
- b .category = property .category
547
- block_list .append (b )
568
+ if property .get ("has_change" , true ):
569
+ b = BLOCKS ["statement_block" ].instantiate ()
570
+ b .block_name = "change_prop_%s " % property .name
571
+ b .block_format = "Change %s by {value: %s} " % [property .name .capitalize (), type_string ]
572
+ b .statement = "%s += {value} " % property .name
573
+ var default_change = property .get ("default_change" , FALLBACK_CHANGE_FOR_TYPE [variant_type ])
574
+ b .defaults = {"value" : default_change }
575
+ b .category = property .category
576
+ block_list .append (b )
548
577
549
578
b = BLOCKS ["parameter_block" ].instantiate ()
550
579
b .block_name = "get_prop_%s " % property .name
@@ -565,7 +594,7 @@ static func blocks_from_property_list(property_list: Array, selected_props: Dict
565
594
for prop in property_list :
566
595
if selected_property == prop .name :
567
596
found_prop = prop
568
- found_prop .category = selected_props [selected_property ]
597
+ found_prop .merge ( selected_props [selected_property ])
569
598
break
570
599
if found_prop :
571
600
block_list .append_array (property_to_blocklist (found_prop ))
@@ -594,15 +623,38 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]:
594
623
match _class_name :
595
624
"Node2D" :
596
625
props = {
597
- "position" : "Transform | Position" ,
598
- "rotation_degrees" : "Transform | Rotation" ,
599
- "scale" : "Transform | Scale" ,
626
+ "position" :
627
+ {
628
+ "category" : "Transform | Position" ,
629
+ "default_set" : "100, 100" ,
630
+ "default_change" : "1, 1" ,
631
+ },
632
+ "rotation_degrees" :
633
+ {
634
+ "category" : "Transform | Rotation" ,
635
+ "default_set" : "45" ,
636
+ "default_change" : "1" ,
637
+ },
638
+ "scale" :
639
+ {
640
+ "category" : "Transform | Scale" ,
641
+ "default_set" : "2, 2" ,
642
+ "default_change" : "0.1, 0.1" ,
643
+ },
600
644
}
601
645
602
646
"CanvasItem" :
603
647
props = {
604
- "modulate" : "Graphics | Modulate" ,
605
- "visible" : "Graphics | Visibility" ,
648
+ "modulate" :
649
+ {
650
+ "category" : "Graphics | Modulate" ,
651
+ "has_change" : false ,
652
+ },
653
+ "visible" :
654
+ {
655
+ "category" : "Graphics | Visibility" ,
656
+ "has_change" : false ,
657
+ },
606
658
}
607
659
608
660
"RigidBody2D" :
@@ -643,9 +695,9 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]:
643
695
block_list .append (b )
644
696
645
697
props = {
646
- "mass" : " Physics | Mass" ,
647
- "linear_velocity" : " Physics | Velocity" ,
648
- "angular_velocity" : " Physics | Velocity" ,
698
+ "mass" : { "category" : " Physics | Mass"} ,
699
+ "linear_velocity" : { "category" : " Physics | Velocity"} ,
700
+ "angular_velocity" : { "category" : " Physics | Velocity"} ,
649
701
}
650
702
651
703
"AnimationPlayer" :
@@ -747,7 +799,7 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]:
747
799
block_list .append (b )
748
800
749
801
props = {
750
- "velocity" : " Physics | Velocity" ,
802
+ "velocity" : { "category" : " Physics | Velocity"} ,
751
803
}
752
804
753
805
var prop_list = ClassDB .class_get_property_list (_class_name , true )
0 commit comments