diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 07bf520..b3b9a32 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -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_res := {} - for from_port: String in outgoing_connections: + for from_port in outgoing_connections: 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] var incoming_connections: Dictionary = nodes.nodes[node_id].incoming_connections as Dictionary var incoming_connections_res := {} - for to_port: String in incoming_connections: + for to_port in incoming_connections: 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] 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) +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. func to_dict(with_meta: bool = true) -> Dictionary: var inner := { diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index a46b356..55b01e9 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -284,16 +284,16 @@ static func from_dict(data: Dictionary) -> DeckNode: 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] 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] node.outgoing_connections[int(from_port)][to_node] = [] for to_input_port in input_ports: 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] for connection in connection_data: connection_data[connection] = int(connection_data[connection]) diff --git a/graph_node_renderer/deck_renderer_graph_edit.gd b/graph_node_renderer/deck_renderer_graph_edit.gd index d638e5c..caa55ad 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.gd +++ b/graph_node_renderer/deck_renderer_graph_edit.gd @@ -259,3 +259,17 @@ func _on_paste_nodes_request() -> void: node_pos = node_pos.snapped(Vector2(snapping_distance, snapping_distance)) 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) diff --git a/graph_node_renderer/deck_renderer_graph_edit.tscn b/graph_node_renderer/deck_renderer_graph_edit.tscn index 9490f13..d941dc1 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.tscn +++ b/graph_node_renderer/deck_renderer_graph_edit.tscn @@ -14,6 +14,7 @@ script = ExtResource("1_pojfs") [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="duplicate_nodes_request" from="." to="." method="_on_duplicate_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="scroll_offset_changed" from="." to="." method="_on_scroll_offset_changed"]