moonshine_behavior/
plugin.rs1use std::marker::PhantomData;
2
3use bevy_app::prelude::*;
4use bevy_reflect::{prelude::*, GetTypeRegistration, Typed};
5
6use crate::{Behavior, Memory, Transition, TransitionSequence};
7
8pub struct BehaviorPlugin<T: Behavior>(PhantomData<T>);
33
34impl<T: Behavior> Default for BehaviorPlugin<T> {
35 fn default() -> Self {
36 Self(PhantomData)
37 }
38}
39
40impl<T: RegisterableBehavior> Plugin for BehaviorPlugin<T> {
41 fn build(&self, app: &mut App) {
42 app.register_type::<Transition<T>>()
43 .register_type::<Memory<T>>()
44 .register_type::<TransitionSequence<T>>()
45 .register_required_components::<T, Transition<T>>();
46 }
47}
48
49#[doc(hidden)]
50pub trait RegisterableBehavior: Behavior + FromReflect + GetTypeRegistration + Typed {}
51
52impl<T: Behavior + FromReflect + GetTypeRegistration + Typed> RegisterableBehavior for T {}