mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
delete nodes, fix grouping
This commit is contained in:
parent
292e7be799
commit
2c7ccb66db
3 changed files with 55 additions and 15 deletions
|
@ -71,7 +71,9 @@ func get_node(uuid: String) -> DeckNode:
|
||||||
|
|
||||||
|
|
||||||
## Attempt to connect two nodes. Returns [code]true[/code] if the connection succeeded.
|
## Attempt to connect two nodes. Returns [code]true[/code] if the connection succeeded.
|
||||||
func connect_nodes(from_node: DeckNode, to_node: DeckNode, from_output_port: int, to_input_port: int) -> bool:
|
func connect_nodes(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int) -> bool:
|
||||||
|
var from_node := get_node(from_node_id)
|
||||||
|
var to_node := get_node(to_node_id)
|
||||||
# check that we can do the type conversion
|
# check that we can do the type conversion
|
||||||
var type_a: DeckType.Types = from_node.get_output_ports()[from_output_port].type
|
var type_a: DeckType.Types = from_node.get_output_ports()[from_output_port].type
|
||||||
var type_b: DeckType.Types = to_node.get_input_ports()[to_input_port].type
|
var type_b: DeckType.Types = to_node.get_input_ports()[to_input_port].type
|
||||||
|
@ -86,9 +88,10 @@ func connect_nodes(from_node: DeckNode, to_node: DeckNode, from_output_port: int
|
||||||
|
|
||||||
|
|
||||||
## Remove a connection from two nodes.
|
## Remove a connection from two nodes.
|
||||||
func disconnect_nodes(from_node: DeckNode, to_node: DeckNode, from_output_port: int, to_input_port: int) -> void:
|
func disconnect_nodes(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int) -> void:
|
||||||
var hash = {to_node._id: to_input_port}.hash()
|
var hash := {to_node_id: to_input_port}.hash()
|
||||||
|
var from_node := get_node(from_node_id)
|
||||||
|
var to_node := get_node(to_node_id)
|
||||||
from_node.remove_outgoing_connection(from_output_port, hash)
|
from_node.remove_outgoing_connection(from_output_port, hash)
|
||||||
to_node.remove_incoming_connection(to_input_port)
|
to_node.remove_incoming_connection(to_input_port)
|
||||||
|
|
||||||
|
@ -99,8 +102,24 @@ func is_empty() -> bool:
|
||||||
|
|
||||||
|
|
||||||
## Remove a node from this deck.
|
## Remove a node from this deck.
|
||||||
func remove_node(uuid: String) -> void:
|
func remove_node(uuid: String, remove_connections: bool = false) -> void:
|
||||||
var node = nodes.get(uuid)
|
var node := get_node(uuid)
|
||||||
|
if node == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
if remove_connections:
|
||||||
|
var outgoing_connections := node.outgoing_connections.duplicate(true)
|
||||||
|
|
||||||
|
for output_port: int in outgoing_connections:
|
||||||
|
for connection: Dictionary in outgoing_connections[output_port]:
|
||||||
|
disconnect_nodes(uuid, connection.keys()[0], output_port, connection.values()[0])
|
||||||
|
|
||||||
|
var incoming_connections := node.incoming_connections.duplicate(true)
|
||||||
|
|
||||||
|
for input_port: int in incoming_connections:
|
||||||
|
for from_node: String in incoming_connections[input_port]:
|
||||||
|
disconnect_nodes(from_node, uuid, incoming_connections[input_port][from_node], input_port)
|
||||||
|
|
||||||
nodes.erase(uuid)
|
nodes.erase(uuid)
|
||||||
|
|
||||||
node_removed.emit(node)
|
node_removed.emit(node)
|
||||||
|
@ -133,15 +152,19 @@ func group_nodes(nodes_to_group: Array) -> Deck:
|
||||||
group.groups[_group_id] = _group
|
group.groups[_group_id] = _group
|
||||||
_group._belonging_to = group
|
_group._belonging_to = group
|
||||||
|
|
||||||
for from_port: int in node.outgoing_connections:
|
var outgoing_connections := node.outgoing_connections.duplicate(true)
|
||||||
for connection: Dictionary in node.outgoing_connections[from_port]:
|
|
||||||
if !(connection.keys()[0] in node_ids_to_keep):
|
|
||||||
disconnect_nodes(node, get_node(connection.keys()[0]), from_port, connection.values()[0])
|
|
||||||
|
|
||||||
for to_port: int in node.incoming_connections:
|
for from_port: int in outgoing_connections:
|
||||||
for from_node: String in node.incoming_connections[to_port]:
|
for connection: Dictionary in outgoing_connections[from_port]:
|
||||||
|
if !(connection.keys()[0] in node_ids_to_keep):
|
||||||
|
disconnect_nodes(node._id, connection.keys()[0], from_port, connection.values()[0])
|
||||||
|
|
||||||
|
var incoming_connections := node.incoming_connections.duplicate(true)
|
||||||
|
|
||||||
|
for to_port: int in incoming_connections:
|
||||||
|
for from_node: String in incoming_connections[to_port]:
|
||||||
if !(from_node in node_ids_to_keep):
|
if !(from_node in node_ids_to_keep):
|
||||||
disconnect_nodes(get_node(from_node), node, node.incoming_connections[to_port].values()[0], to_port)
|
disconnect_nodes(from_node, node._id, incoming_connections[to_port][from_node], to_port)
|
||||||
|
|
||||||
midpoint += node.position_as_vector2()
|
midpoint += node.position_as_vector2()
|
||||||
remove_node(node._id)
|
remove_node(node._id)
|
||||||
|
|
|
@ -55,7 +55,7 @@ func attempt_connection(from_node_name: StringName, from_port: int, to_node_name
|
||||||
#var from_output := from_node_renderer.node.get_global_port_idx_from_output(from_port)
|
#var from_output := from_node_renderer.node.get_global_port_idx_from_output(from_port)
|
||||||
#var to_input := to_node_renderer.node.get_global_port_idx_from_input(to_port)
|
#var to_input := to_node_renderer.node.get_global_port_idx_from_input(to_port)
|
||||||
|
|
||||||
if deck.connect_nodes(from_node_renderer.node, to_node_renderer.node, from_port, to_port):
|
if deck.connect_nodes(from_node_renderer.node._id, to_node_renderer.node._id, from_port, to_port):
|
||||||
connect_node(
|
connect_node(
|
||||||
from_node_renderer.name,
|
from_node_renderer.name,
|
||||||
from_port,
|
from_port,
|
||||||
|
@ -72,7 +72,7 @@ func attempt_disconnect(from_node_name: StringName, from_port: int, to_node_name
|
||||||
#var from_output := from_node_renderer.node.get_global_port_idx_from_output(from_port)
|
#var from_output := from_node_renderer.node.get_global_port_idx_from_output(from_port)
|
||||||
#var to_input := to_node_renderer.node.get_global_port_idx_from_input(to_port)
|
#var to_input := to_node_renderer.node.get_global_port_idx_from_input(to_port)
|
||||||
|
|
||||||
deck.disconnect_nodes(from_node_renderer.node, to_node_renderer.node, from_port, to_port)
|
deck.disconnect_nodes(from_node_renderer.node._id, to_node_renderer.node._id, from_port, to_port)
|
||||||
|
|
||||||
disconnect_node(
|
disconnect_node(
|
||||||
from_node_renderer.name,
|
from_node_renderer.name,
|
||||||
|
@ -119,6 +119,7 @@ func initialize_from_deck() -> void:
|
||||||
## Loops through all [DeckNode]s in [member Deck.nodes] and calls
|
## Loops through all [DeckNode]s in [member Deck.nodes] and calls
|
||||||
## [method GraphEdit.connect_node] for all the connections that exist in each
|
## [method GraphEdit.connect_node] for all the connections that exist in each
|
||||||
func refresh_connections() -> void:
|
func refresh_connections() -> void:
|
||||||
|
print(deck.nodes.size())
|
||||||
for node_id in deck.nodes:
|
for node_id in deck.nodes:
|
||||||
var node: DeckNode = deck.nodes[node_id]
|
var node: DeckNode = deck.nodes[node_id]
|
||||||
var from_node: DeckNodeRendererGraphNode = get_children().filter(
|
var from_node: DeckNodeRendererGraphNode = get_children().filter(
|
||||||
|
@ -223,3 +224,18 @@ func _on_add_node_menu_node_selected(type: String) -> void:
|
||||||
get_node_renderer(node).position_offset = node_pos
|
get_node_renderer(node).position_offset = node_pos
|
||||||
|
|
||||||
search_popup_panel.hide()
|
search_popup_panel.hide()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_delete_nodes_request(nodes: Array[StringName]) -> void:
|
||||||
|
var node_ids := nodes.map(
|
||||||
|
func(n: StringName):
|
||||||
|
return (get_node(NodePath(n)) as DeckNodeRendererGraphNode).node._id
|
||||||
|
)
|
||||||
|
|
||||||
|
clear_connections()
|
||||||
|
|
||||||
|
for node_id in node_ids:
|
||||||
|
deck.remove_node(node_id, true)
|
||||||
|
|
||||||
|
#await get_tree().process_frame
|
||||||
|
refresh_connections()
|
||||||
|
|
|
@ -12,5 +12,6 @@ right_disconnects = true
|
||||||
show_arrange_button = false
|
show_arrange_button = false
|
||||||
script = ExtResource("1_pojfs")
|
script = ExtResource("1_pojfs")
|
||||||
|
|
||||||
|
[connection signal="delete_nodes_request" from="." to="." method="_on_delete_nodes_request"]
|
||||||
[connection signal="popup_request" from="." to="." method="_on_popup_request"]
|
[connection signal="popup_request" from="." to="." method="_on_popup_request"]
|
||||||
[connection signal="scroll_offset_changed" from="." to="." method="_on_scroll_offset_changed"]
|
[connection signal="scroll_offset_changed" from="." to="." method="_on_scroll_offset_changed"]
|
||||||
|
|
Loading…
Reference in a new issue