use crate::utils::behavior::BaseBehavior;
use crate::{
core::{pool::Handle, visitor::prelude::*},
utils::behavior::{BehaviorNode, BehaviorTree},
};
#[derive(Debug, PartialEq, Visit, Eq, Clone, Default)]
pub enum CompositeNodeKind {
#[default]
Sequence,
Selector,
}
#[derive(Debug, PartialEq, Visit, Eq, Clone)]
pub struct CompositeNode<B>
where
B: BaseBehavior,
{
pub children: Vec<Handle<BehaviorNode<B>>>,
pub kind: CompositeNodeKind,
}
impl<B> Default for CompositeNode<B>
where
B: BaseBehavior,
{
fn default() -> Self {
Self {
children: Default::default(),
kind: Default::default(),
}
}
}
impl<B> CompositeNode<B>
where
B: BaseBehavior,
{
pub fn new(kind: CompositeNodeKind, children: Vec<Handle<BehaviorNode<B>>>) -> Self {
Self { children, kind }
}
pub fn new_sequence(children: Vec<Handle<BehaviorNode<B>>>) -> Self {
Self {
children,
kind: CompositeNodeKind::Sequence,
}
}
pub fn new_selector(children: Vec<Handle<BehaviorNode<B>>>) -> Self {
Self {
children,
kind: CompositeNodeKind::Selector,
}
}
pub fn add_to(self, tree: &mut BehaviorTree<B>) -> Handle<BehaviorNode<B>> {
tree.add_node(BehaviorNode::Composite(self))
}
}