Переглянути джерело

Merge pull request #101439 from JekSun97/Provide-connection_map-to-GraphEdit

Add `get_connection_list_from_node` function to `GraphEdit`
Thaddeus Crews 5 місяців тому
батько
коміт
0822829359
3 змінених файлів з 35 додано та 0 видалено
  1. 17 0
      doc/classes/GraphEdit.xml
  2. 17 0
      scene/gui/graph_edit.cpp
  3. 1 0
      scene/gui/graph_edit.h

+ 17 - 0
doc/classes/GraphEdit.xml

@@ -208,6 +208,23 @@
 				Returns the points which would make up a connection between [param from_node] and [param to_node].
 			</description>
 		</method>
+		<method name="get_connection_list_from_node" qualifiers="const">
+			<return type="Dictionary[]" />
+			<param index="0" name="node" type="StringName" />
+			<description>
+				Returns an [Array] containing a list of all connections for [param node].
+				A connection is represented as a [Dictionary] in the form of:
+				[codeblock]
+				{
+				    from_node: StringName,
+				    from_port: int,
+				    to_node: StringName,
+				    to_port: int,
+				    keep_alive: bool
+				}
+				[/codeblock]
+			</description>
+		</method>
 		<method name="get_connections_intersecting_with_rect" qualifiers="const">
 			<return type="Dictionary[]" />
 			<param index="0" name="rect" type="Rect2" />

+ 17 - 0
scene/gui/graph_edit.cpp

@@ -2329,6 +2329,22 @@ TypedArray<Dictionary> GraphEdit::_get_connections_intersecting_with_rect(const
 	return arr;
 }
 
+TypedArray<Dictionary> GraphEdit::_get_connection_list_from_node(const StringName &p_node) const {
+	List<Ref<GraphEdit::Connection>> connections_from_node = connection_map.get(p_node);
+	TypedArray<Dictionary> connections_from_node_dict;
+
+	for (const Ref<Connection> &conn : connections_from_node) {
+		Dictionary d;
+		d["from_node"] = conn->from_node;
+		d["from_port"] = conn->from_port;
+		d["to_node"] = conn->to_node;
+		d["to_port"] = conn->to_port;
+		d["keep_alive"] = conn->keep_alive;
+		connections_from_node_dict.push_back(d);
+	}
+	return connections_from_node_dict;
+}
+
 void GraphEdit::_zoom_minus() {
 	set_zoom(zoom / zoom_step);
 }
@@ -2689,6 +2705,7 @@ void GraphEdit::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_connection_list"), &GraphEdit::_get_connection_list);
 	ClassDB::bind_method(D_METHOD("get_connection_count", "from_node", "from_port"), &GraphEdit::get_connection_count);
 	ClassDB::bind_method(D_METHOD("get_closest_connection_at_point", "point", "max_distance"), &GraphEdit::_get_closest_connection_at_point, DEFVAL(4.0));
+	ClassDB::bind_method(D_METHOD("get_connection_list_from_node", "node"), &GraphEdit::_get_connection_list_from_node);
 	ClassDB::bind_method(D_METHOD("get_connections_intersecting_with_rect", "rect"), &GraphEdit::_get_connections_intersecting_with_rect);
 	ClassDB::bind_method(D_METHOD("clear_connections"), &GraphEdit::clear_connections);
 	ClassDB::bind_method(D_METHOD("force_connection_drag_end"), &GraphEdit::force_connection_drag_end);

+ 1 - 0
scene/gui/graph_edit.h

@@ -344,6 +344,7 @@ private:
 	TypedArray<Dictionary> _get_connection_list() const;
 	Dictionary _get_closest_connection_at_point(const Vector2 &p_point, float p_max_distance = 4.0) const;
 	TypedArray<Dictionary> _get_connections_intersecting_with_rect(const Rect2 &p_rect) const;
+	TypedArray<Dictionary> _get_connection_list_from_node(const StringName &p_node) const;
 
 	Rect2 _compute_shrinked_frame_rect(const GraphFrame *p_frame);
 	void _set_drag_frame_attached_nodes(GraphFrame *p_frame, bool p_drag);