@@ -4,9 +4,11 @@ extends MarginContainer
4
4
const ASTList = preload ("res://addons/block_code/code_generation/ast_list.gd" )
5
5
const BlockAST = preload ("res://addons/block_code/code_generation/block_ast.gd" )
6
6
const BlockCodePlugin = preload ("res://addons/block_code/block_code_plugin.gd" )
7
+ const BlockDefinition = preload ("res://addons/block_code/code_generation/block_definition.gd" )
7
8
const BlockTreeUtil = preload ("res://addons/block_code/ui/block_tree_util.gd" )
8
9
const DragManager = preload ("res://addons/block_code/drag_manager/drag_manager.gd" )
9
10
const ScriptGenerator = preload ("res://addons/block_code/code_generation/script_generator.gd" )
11
+ const Types = preload ("res://addons/block_code/types/types.gd" )
10
12
const Util = preload ("res://addons/block_code/ui/util.gd" )
11
13
12
14
const EXTEND_MARGIN : float = 800
@@ -75,6 +77,10 @@ func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
75
77
if typeof (data ) != TYPE_DICTIONARY :
76
78
return false
77
79
80
+ # Allow dropping property block
81
+ if data .get ("type" , "" ) == "obj_property" :
82
+ return true
83
+
78
84
var nodes : Array = data .get ("nodes" , [])
79
85
if nodes .size () != 1 :
80
86
return false
@@ -94,6 +100,8 @@ func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
94
100
func _drop_data (at_position : Vector2 , data : Variant ) -> void :
95
101
if data ["type" ] == "nodes" :
96
102
_drop_node (at_position , data )
103
+ elif data ["type" ] == "obj_property" :
104
+ _drop_obj_property (at_position , data )
97
105
98
106
99
107
func _drop_node (at_position : Vector2 , data : Variant ) -> void :
@@ -113,6 +121,30 @@ func _drop_node(at_position: Vector2, data: Variant) -> void:
113
121
reconnect_block .emit (block )
114
122
115
123
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
+
116
148
func add_block (block : Block , position : Vector2 = Vector2 .ZERO ) -> void :
117
149
if block is EntryBlock :
118
150
block .position = canvas_to_window (position ).snapped (SNAP_GRID )
0 commit comments