use crate::simple_bt::{BehaviorArc, BehaviorNode, Blackboard, NodeResult};
use std::sync::Arc;
/// Always succeedes.
#[derive(Debug)]
pub struct Succeeder {
child: Option<Arc<dyn BehaviorNode>>,
}
impl Default for Succeeder {
fn default() -> Self {
Self { child: None }
}
}
impl Succeeder {
pub fn new(child: Arc<dyn BehaviorNode>) -> Self {
Self { child: Some(child) }
}
}
impl From<BehaviorArc> for Succeeder {
fn from(value: BehaviorArc) -> Self {
Self {
child: Some(value.0.clone()),
}
}
}
impl BehaviorNode for Succeeder {
fn tick(
&self,
blackboard: &mut Blackboard,
commands: &mut bevy::prelude::Commands,
) -> crate::simple_bt::NodeResult {
if let Some(child) = self.child.as_ref() {
match child.tick(blackboard, commands) {
NodeResult::Failure | NodeResult::Success => NodeResult::Success,
NodeResult::Running(resume) => NodeResult::Running(Succeeder::from(resume).into()),
}
} else {
NodeResult::Success
}
}
}
#[cfg(test)]
mod tests {}