diff --git a/crates/valence_command/src/graph.rs b/crates/valence_command/src/graph.rs index 3712a043e..df23f5346 100644 --- a/crates/valence_command/src/graph.rs +++ b/crates/valence_command/src/graph.rs @@ -153,87 +153,6 @@ impl Display for CommandEdgeType { impl From for CommandTreeS2c { fn from(command_graph: CommandGraph) -> Self { - - let mut nodes = Vec::new(); - let graph = value.graph; - let root_index_graph = value.root; - let root_index = 0; - let mut nodes_to_be_allocated = Vec::new(); - - // Find all the nodes children and redirects that have to happen - for node in graph.node_indices() { - let mut children = Vec::new(); - - let mut redirect_node = None; - for edge in graph.edges_directed(node, Outgoing) { - match edge.weight() { - CommandEdgeType::Redirect => redirect_node = Some(edge.target()), - CommandEdgeType::Child => children.push(edge.target()), - } - } - - // we dont actually know where in the list the redirect node and children are - // yet, so we have to do this - nodes_to_be_allocated.push((node, children, redirect_node)); - } - - let mut index_map: HashMap = HashMap::new(); - - // Finalise the index of all nodes in the vec - for (index, _, _) in &nodes_to_be_allocated { - let mut node = CommandNode { - executable: false, - data: NodeData::Root, - scopes: Vec::new(), - }; - - if *index == root_index_graph { - nodes.push(node); - index_map.insert(*index, nodes.len() - 1); - continue; - } else { - let node_data = graph.node_weight(*index).unwrap(); - node.data = node_data.data.clone(); - node.executable = node_data.executable; - node.scopes = node_data.scopes.clone(); - } - - nodes.push(CommandNode { - executable: node.executable, - data: node.data, - scopes: node.scopes, - }); - - index_map.insert(*index, nodes.len() - 1); - } - - let mut packet_nodes = Vec::new(); - - // convert the nodes to the packet format - for (index, children, redirect) in &nodes_to_be_allocated { - let mut packet_children: Vec = Vec::new(); - - for child in children { - packet_children.push((index_map[child] as i32).into()) - } - - let packet_redirect: Option = - redirect.map(|towards| (index_map[&towards] as i32).into()); - - packet_nodes.push(Node { - children: packet_children, - data: nodes[index_map[index]].data.clone().into(), - executable: nodes[index_map[index]].executable, - redirect_node: packet_redirect, - }); - } - - // insert the children and the redirects - CommandTreeS2c { - commands: packet_nodes, - root_index: root_index.into(), - } - let graph = command_graph.graph; let nodes_and_edges = graph.into_nodes_edges();