1pub mod animation;
2pub mod state;
3pub mod util;
4
5#[cfg(feature = "aseprite")]
6pub mod aseprite;
7
8use bevy::{ecs::system::EntityCommands, prelude::*};
9use animation::Animation;
10
11pub mod prelude {
12 pub use crate::AnimatorPlugin;
13 pub use crate::animation::{Animation, Animator, AnimationPlugin};
14 pub use crate::state::{AnimationState, AnimationStatePlugin};
15 pub use crate::{InitAnimationCommand, InsertAnimationCommand};
16
17 #[cfg(feature = "aseprite")]
18 pub use crate::aseprite::{Aseprite, AsepriteAnimation};
19}
20
21pub struct AnimatorPlugin;
27
28impl Plugin for AnimatorPlugin {
29 fn build(&self, app: &mut App) {
30 if cfg!(feature = "aseprite") {
31 app
32 .add_plugins(aseprite::AsepriteAnimationPlugin)
33 ;
34 }
35 }
36}
37
38pub trait InitAnimationCommand {
43 fn init_animation<A : Animation + FromWorld + Send + Sync + 'static>(&mut self, path : &str) -> EntityCommands;
44}
45
46impl <'w, 's> InitAnimationCommand for Commands<'w, 's> {
47 fn init_animation<A : Animation + FromWorld + Send + Sync + 'static>(&mut self, path : &str) -> EntityCommands {
48 let entity = self.spawn_empty().id();
49 let path = path.to_string();
50 self.add(move |world : &mut World| {
51 A::spawn(None, world, path, entity);
52 });
53 self.entity(entity)
54 }
55}
56
57pub trait InsertAnimationCommand {
58 fn insert_animation<A : Animation + Send + Sync + 'static>(&mut self, animation : A, path : &str) -> EntityCommands;
59}
60
61impl <'w, 's> InsertAnimationCommand for Commands<'w, 's> {
62 fn insert_animation<A : Animation + Send + Sync + 'static>(&mut self, animation : A, path : &str) -> EntityCommands {
63 let entity = self.spawn_empty().id();
64 let path = path.to_string();
65 self.add(move |world : &mut World| {
66 A::spawn(Some(animation), world, path, entity);
67 });
68 self.entity(entity)
69 }
70}