use std::fmt::Debug;
use crate::control::{CTreeNodeID, ChildUpdate, ControlTree, LeafNode};
use crate::Status;
pub trait Control {
fn tick(&mut self) -> Status;
fn child_updated(&mut self, update: ChildUpdate);
fn all_children_seen(&mut self) {}
}
pub trait ExecutorHook {
fn hook(&mut self, leaf: &LeafNode) -> Status;
}
pub trait Decorator: Clone {
fn init(&mut self);
fn child_updated(&mut self, update: ChildUpdate) -> Status;
fn status(&self) -> Status;
fn reset(&mut self);
fn name(&self) -> String;
fn details(&self) -> Option<String> {
None
}
fn reset_request(&mut self) -> Option<CTreeNodeID> {
None
}
}
pub trait UpdateCallback<D: Decorator> {
fn callback(&mut self, state: &ControlTree<D>);
}
pub struct NoCallback;
impl<D: Decorator> UpdateCallback<D> for NoCallback {
fn callback(&mut self, _state: &ControlTree<D>) {}
}
pub trait Executor<BB: Blackboard>: Clone + Debug {
fn execute(&self, blackboard: &mut BB) -> Status;
fn name(&self) -> Option<String> {
None
}
fn details(&self) -> Option<String> {
None
}
}
pub trait Conditional<BB: Blackboard>: Clone + Debug {
fn conditional(&self, blackboard: &BB) -> Status;
fn name(&self) -> Option<String> {
None
}
fn details(&self) -> Option<String> {
None
}
}
pub trait Blackboard: Default + Clone + Debug {}
impl<T> Blackboard for T where T: Default + Clone + Debug {}
pub trait ActionHandler: Clone {
type Bb: Blackboard;
type Execute: Executor<Self::Bb>;
type Condition: Conditional<Self::Bb>;
}