feat: tie dialog to graph

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-05-09 14:10:43 +02:00
parent 7cead58ed3
commit 547d34782c
5 changed files with 143 additions and 6 deletions

View File

@@ -126,6 +126,17 @@ impl GraphExplorer<'_> {
Ok(())
}
pub(crate) fn get_current_path(&self) -> Vec<String> {
let graph = self.linearize_graph();
let position_items = &self.inner.current_position;
if let Some(graph) = graph {
graph.to_current_path(position_items)
} else {
Vec::new()
}
}
}
trait RenderGraph {
@@ -332,6 +343,22 @@ impl MovementGraph {
None => Some(self),
}
}
fn to_current_path(&self, position_items: &[usize]) -> Vec<String> {
match position_items.split_first() {
Some((first, rest)) => match self.items.get(*first) {
Some(item) => {
let mut current = vec![item.name.clone()];
let mut next = item.values.to_current_path(rest);
current.append(&mut next);
current
}
None => Vec::new(),
},
None => Vec::new(),
}
}
}
impl From<Box<GraphItem>> for MovementGraph {