crate::ix!();
impl fmt::Display for StrippedStringSkeleton {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut items = self.items().clone();
items.sort_by(|a,b| a.kind().cmp(b.kind()));
for node in items {
write!(f, "{} => ", node.name())?;
match node.kind() {
SkillTreeNodeKind::Dispatch => {
writeln!(f, "Dispatch node with branches: {{")?;
if let Some(children) = node.children() {
for child_spec in children {
writeln!(
f,
" // branch_selection_probability = {}%",
child_spec.probability()
)?;
writeln!(f, " {},", child_spec.name())?;
}
}
writeln!(f, "}}")?;
}
SkillTreeNodeKind::Aggregate => {
writeln!(f, "Aggregate node with components: [")?;
if let Some(children) = node.children() {
for child_spec in children {
let nm = child_spec.name();
if *child_spec.optional() {
writeln!(
f,
" {}, // optional, psome={}%",
nm,
child_spec.probability()
)?;
} else {
writeln!(f, " {}, // mandatory", nm)?;
}
}
}
writeln!(f, "]")?;
}
SkillTreeNodeKind::LeafHolder => {
write!(f, "LeafHolder node")?;
if let Some(n) = node.n_leaves() {
write!(f, " with {} leaves", n)?;
}
if let Some(true) = node.capstone() {
write!(f, " [capstone]")?;
}
writeln!(f)?;
}
}
writeln!(f)?;
}
Ok(())
}
}