Skip to content

Commit

Permalink
fix lol
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCrumpLeys committed Sep 11, 2023
1 parent 6216e50 commit 4433a10
Showing 1 changed file with 0 additions and 81 deletions.
81 changes: 0 additions & 81 deletions crates/valence_command/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,87 +153,6 @@ impl Display for CommandEdgeType {

impl From<CommandGraph> 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<NodeIndex, usize> = 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<VarInt> = Vec::new();

for child in children {
packet_children.push((index_map[child] as i32).into())
}

let packet_redirect: Option<VarInt> =
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;

Check warning on line 156 in crates/valence_command/src/graph.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/valence/valence/crates/valence_command/src/graph.rs
let nodes_and_edges = graph.into_nodes_edges();

Expand Down

0 comments on commit 4433a10

Please sign in to comment.