moonshine_behavior/
plugin.rs1use std::marker::PhantomData;
2
3use bevy_app::prelude::*;
4use bevy_reflect::{prelude::*, GetTypeRegistration, Typed};
5
6use crate::events::BehaviorEventsPlugin;
7use crate::{Behavior, Memory, Transition, TransitionSequence};
8
9pub struct BehaviorPlugin<T: Behavior>(PhantomData<T>);
10
11impl<T: Behavior> Default for BehaviorPlugin<T> {
12 fn default() -> Self {
13 Self(PhantomData)
14 }
15}
16
17impl<T: RegisterableBehavior> Plugin for BehaviorPlugin<T> {
18 fn build(&self, app: &mut App) {
19 app.add_plugins(BehaviorEventsPlugin::<T>::default())
20 .register_type::<Transition<T>>()
21 .register_type::<Memory<T>>()
22 .register_type::<TransitionSequence<T>>()
23 .register_required_components::<T, Transition<T>>();
24 }
25}
26
27pub trait RegisterableBehavior: Behavior + FromReflect + GetTypeRegistration + Typed {}
28
29impl<T: Behavior + FromReflect + GetTypeRegistration + Typed> RegisterableBehavior for T {}