use std::collections::HashMap;
use std::rc::Rc;
use arora_behavior::{Behavior, BehaviorContext, BehaviorError, BehaviorStatus};
use uuid::Uuid;
use crate::{run_behavior_tree, BehaviorTree, ModuleFunction};
pub struct TreeBehavior {
tree: BehaviorTree,
function_index: Rc<HashMap<Uuid, ModuleFunction>>,
}
impl TreeBehavior {
pub fn new(tree: BehaviorTree, function_index: Rc<HashMap<Uuid, ModuleFunction>>) -> Self {
Self {
tree,
function_index,
}
}
}
impl Behavior for TreeBehavior {
fn tick(&mut self, ctx: &mut BehaviorContext) -> Result<BehaviorStatus, BehaviorError> {
run_behavior_tree(&self.tree, self.function_index.clone(), ctx.caller, false).map_err(
|e| BehaviorError {
message: format!("behavior tree: {e:?}"),
},
)?;
Ok(BehaviorStatus::Done)
}
}