mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
add duplicating nodes
This commit is contained in:
parent
364b4a2070
commit
c5512cfee7
4 changed files with 31 additions and 7 deletions
|
@ -258,16 +258,16 @@ func paste_nodes_from_dict(nodes: Dictionary, position: Vector2 = Vector2()) ->
|
||||||
|
|
||||||
var outgoing_connections: Dictionary = nodes.nodes[node_id].outgoing_connections as Dictionary
|
var outgoing_connections: Dictionary = nodes.nodes[node_id].outgoing_connections as Dictionary
|
||||||
var outgoing_connections_res := {}
|
var outgoing_connections_res := {}
|
||||||
for from_port: String in outgoing_connections:
|
for from_port in outgoing_connections:
|
||||||
outgoing_connections_res[from_port] = {}
|
outgoing_connections_res[from_port] = {}
|
||||||
for to_node_id: String in outgoing_connections[from_port]:
|
for to_node_id in outgoing_connections[from_port]:
|
||||||
outgoing_connections_res[from_port][ids_map[to_node_id]] = outgoing_connections[from_port][to_node_id]
|
outgoing_connections_res[from_port][ids_map[to_node_id]] = outgoing_connections[from_port][to_node_id]
|
||||||
|
|
||||||
var incoming_connections: Dictionary = nodes.nodes[node_id].incoming_connections as Dictionary
|
var incoming_connections: Dictionary = nodes.nodes[node_id].incoming_connections as Dictionary
|
||||||
var incoming_connections_res := {}
|
var incoming_connections_res := {}
|
||||||
for to_port: String in incoming_connections:
|
for to_port in incoming_connections:
|
||||||
incoming_connections_res[to_port] = {}
|
incoming_connections_res[to_port] = {}
|
||||||
for from_node_id: String in incoming_connections[to_port]:
|
for from_node_id in incoming_connections[to_port]:
|
||||||
incoming_connections_res[to_port][ids_map[from_node_id]] = incoming_connections[to_port][from_node_id]
|
incoming_connections_res[to_port][ids_map[from_node_id]] = incoming_connections[to_port][from_node_id]
|
||||||
|
|
||||||
nodes.nodes[node_id].outgoing_connections = outgoing_connections_res
|
nodes.nodes[node_id].outgoing_connections = outgoing_connections_res
|
||||||
|
@ -281,6 +281,15 @@ func paste_nodes_from_json(json: String, position: Vector2 = Vector2()) -> void:
|
||||||
paste_nodes_from_dict(JSON.parse_string(json), position)
|
paste_nodes_from_dict(JSON.parse_string(json), position)
|
||||||
|
|
||||||
|
|
||||||
|
func duplicate_nodes(nodes: Array[String]) -> void:
|
||||||
|
if nodes.is_empty():
|
||||||
|
return
|
||||||
|
|
||||||
|
var position := get_node(nodes[0]).position_as_vector2() + Vector2(50, 50)
|
||||||
|
var d := copy_nodes(nodes)
|
||||||
|
paste_nodes_from_dict(d, position)
|
||||||
|
|
||||||
|
|
||||||
## Returns a [Dictionary] representation of this deck.
|
## Returns a [Dictionary] representation of this deck.
|
||||||
func to_dict(with_meta: bool = true) -> Dictionary:
|
func to_dict(with_meta: bool = true) -> Dictionary:
|
||||||
var inner := {
|
var inner := {
|
||||||
|
|
|
@ -284,16 +284,16 @@ static func from_dict(data: Dictionary) -> DeckNode:
|
||||||
|
|
||||||
node._pre_connection()
|
node._pre_connection()
|
||||||
|
|
||||||
for from_port: String in data.outgoing_connections:
|
for from_port in data.outgoing_connections:
|
||||||
var connection_data: Dictionary = data.outgoing_connections[from_port]
|
var connection_data: Dictionary = data.outgoing_connections[from_port]
|
||||||
node.outgoing_connections[int(from_port)] = {}
|
node.outgoing_connections[int(from_port)] = {}
|
||||||
for to_node: String in connection_data:
|
for to_node in connection_data:
|
||||||
var input_ports: Array = connection_data[to_node]
|
var input_ports: Array = connection_data[to_node]
|
||||||
node.outgoing_connections[int(from_port)][to_node] = []
|
node.outgoing_connections[int(from_port)][to_node] = []
|
||||||
for to_input_port in input_ports:
|
for to_input_port in input_ports:
|
||||||
node.outgoing_connections[int(from_port)][to_node].append(int(to_input_port))
|
node.outgoing_connections[int(from_port)][to_node].append(int(to_input_port))
|
||||||
|
|
||||||
for to_port: String in data.incoming_connections:
|
for to_port in data.incoming_connections:
|
||||||
var connection_data = data.incoming_connections[to_port]
|
var connection_data = data.incoming_connections[to_port]
|
||||||
for connection in connection_data:
|
for connection in connection_data:
|
||||||
connection_data[connection] = int(connection_data[connection])
|
connection_data[connection] = int(connection_data[connection])
|
||||||
|
|
|
@ -259,3 +259,17 @@ func _on_paste_nodes_request() -> void:
|
||||||
node_pos = node_pos.snapped(Vector2(snapping_distance, snapping_distance))
|
node_pos = node_pos.snapped(Vector2(snapping_distance, snapping_distance))
|
||||||
|
|
||||||
deck.paste_nodes_from_json(clip, node_pos)
|
deck.paste_nodes_from_json(clip, node_pos)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_duplicate_nodes_request() -> void:
|
||||||
|
var selected := get_selected_nodes()
|
||||||
|
if selected.is_empty():
|
||||||
|
return
|
||||||
|
|
||||||
|
var selected_ids: Array[String]
|
||||||
|
selected_ids.assign(selected.map(
|
||||||
|
func(x: DeckNodeRendererGraphNode):
|
||||||
|
return x.node._id
|
||||||
|
))
|
||||||
|
|
||||||
|
deck.duplicate_nodes(selected_ids)
|
||||||
|
|
|
@ -14,6 +14,7 @@ script = ExtResource("1_pojfs")
|
||||||
|
|
||||||
[connection signal="copy_nodes_request" from="." to="." method="_on_copy_nodes_request"]
|
[connection signal="copy_nodes_request" from="." to="." method="_on_copy_nodes_request"]
|
||||||
[connection signal="delete_nodes_request" from="." to="." method="_on_delete_nodes_request"]
|
[connection signal="delete_nodes_request" from="." to="." method="_on_delete_nodes_request"]
|
||||||
|
[connection signal="duplicate_nodes_request" from="." to="." method="_on_duplicate_nodes_request"]
|
||||||
[connection signal="paste_nodes_request" from="." to="." method="_on_paste_nodes_request"]
|
[connection signal="paste_nodes_request" from="." to="." method="_on_paste_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