Browse Source

added disconnecting cables is an inlet is removed

Jonathan Higgins 3 months ago
parent
commit
0f50f056bc
2 changed files with 9 additions and 0 deletions
  1. 2 0
      scenes/Nodes/node_logic.gd
  2. 7 0
      scenes/main/scripts/graph_edit.gd

+ 2 - 0
scenes/Nodes/node_logic.gd

@@ -2,6 +2,7 @@ extends GraphNode
 
 @export var min_gap: float = 0.5  # editable value in inspector for the minimum gap between min and max
 signal open_help
+signal inlet_removed
 
 func _ready() -> void:
 	var sliders := _get_all_hsliders(self) #finds all sliders
@@ -83,6 +84,7 @@ func remove_inlet_from_node():
 	var inlet_count = self.get_input_port_count()
 	var child_count = self.get_child_count()
 	
+	inlet_removed.emit(self.get_name(), child_count - 1)
 	set_slot(inlet_count - 1, false, get_input_port_type(0), get_input_port_color(0), false, 0, get_input_port_color(0))
 	
 	if get_child(child_count - 2).has_meta("dummynode"):

+ 7 - 0
scenes/main/scripts/graph_edit.gd

@@ -289,6 +289,7 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 			
 			add_child(graphnode, true)
 			graphnode.connect("open_help", open_help)
+			graphnode.connect("inlet_removed", Callable(self, "on_inlet_removed"))
 			_register_inputs_in_node(graphnode) #link sliders for changes tracking
 			_register_node_movement() #link nodes for tracking position changes for changes tracking
 			
@@ -577,3 +578,9 @@ func _on_paste_nodes_request() -> void:
 	control_script.simulate_mouse_click() #hacky fix to stop tooltips getting stuck
 	await get_tree().process_frame
 	graph_edit.paste_copied_nodes()
+
+func on_inlet_removed(node_name: StringName, port_index: int):
+	var connections = get_connection_list()
+	for conn in connections:
+		if conn.to_node == node_name and conn.to_port == port_index:
+			disconnect_node(conn.from_node, conn.from_port, conn.to_node, conn.to_port)