@@ -4,9 +4,11 @@ extends MarginContainer
44const ASTList = preload ("res://addons/block_code/code_generation/ast_list.gd" )
55const BlockAST = preload ("res://addons/block_code/code_generation/block_ast.gd" )
66const BlockCodePlugin = preload ("res://addons/block_code/block_code_plugin.gd" )
7+ const BlockDefinition = preload ("res://addons/block_code/code_generation/block_definition.gd" )
78const BlockTreeUtil = preload ("res://addons/block_code/ui/block_tree_util.gd" )
89const DragManager = preload ("res://addons/block_code/drag_manager/drag_manager.gd" )
910const ScriptGenerator = preload ("res://addons/block_code/code_generation/script_generator.gd" )
11+ const Types = preload ("res://addons/block_code/types/types.gd" )
1012const Util = preload ("res://addons/block_code/ui/util.gd" )
1113
1214const EXTEND_MARGIN : float = 800
@@ -75,6 +77,10 @@ func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
7577 if typeof (data ) != TYPE_DICTIONARY :
7678 return false
7779
80+ # Allow dropping property block
81+ if data .get ("type" , "" ) == "obj_property" :
82+ return true
83+
7884 var nodes : Array = data .get ("nodes" , [])
7985 if nodes .size () != 1 :
8086 return false
@@ -94,6 +100,8 @@ func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
94100func _drop_data (at_position : Vector2 , data : Variant ) -> void :
95101 if data ["type" ] == "nodes" :
96102 _drop_node (at_position , data )
103+ elif data ["type" ] == "obj_property" :
104+ _drop_obj_property (at_position , data )
97105
98106
99107func _drop_node (at_position : Vector2 , data : Variant ) -> void :
@@ -113,6 +121,30 @@ func _drop_node(at_position: Vector2, data: Variant) -> void:
113121 reconnect_block .emit (block )
114122
115123
124+ func _drop_obj_property (at_position : Vector2 , data : Variant ) -> void :
125+ var object_name = str (data ["object" ]).get_slice (":" , 0 )
126+ var property_name = data ["property" ]
127+ var property_value = data ["value" ]
128+
129+ # Prepare a block to get the property's value
130+ var block_definition = (
131+ BlockDefinition
132+ . new (
133+ & "% s_get_% s" % [object_name , property_name ],
134+ object_name ,
135+ "The %s property" % property_name ,
136+ "Variables" ,
137+ Types .BlockType .VALUE ,
138+ typeof (property_value ),
139+ "%s " % property_name .capitalize ().to_lower (),
140+ "%s " % property_name ,
141+ )
142+ )
143+ var block = _context .block_script .instantiate_block (block_definition )
144+ add_block (block , at_position )
145+ reconnect_block .emit (block )
146+
147+
116148func add_block (block : Block , position : Vector2 = Vector2 .ZERO ) -> void :
117149 if block is EntryBlock :
118150 block .position = canvas_to_window (position ).snapped (SNAP_GRID )
0 commit comments