diff --git a/src/tweenable.rs b/src/tweenable.rs index 1c4b4c9..685f081 100644 --- a/src/tweenable.rs +++ b/src/tweenable.rs @@ -436,7 +436,7 @@ pub struct Tween { lens: Box + Send + Sync + 'static>, on_completed: Option>>>, event_data: Option, - system_id: Option, + system_id: Option>, } impl Tween { @@ -584,15 +584,16 @@ impl Tween { /// Enable running a one-shot system upon completion. /// /// If enabled, the tween will run a system via a provided [`SystemId`] when - /// the animation completes. This is similar to the - /// [`with_completed()`], but uses a system registered by - /// [`register_system()`] instead of a callback. + /// the animation completes. The system receives the [`Entity`] the animator + /// is attached to as its input. This is similar to [`with_completed()`], + /// but uses a system registered by [`register_system()`] instead of a + /// callback. /// /// # Example /// /// ``` /// # use bevy_tweening::{lens::*, *}; - /// # use bevy::{ecs::event::EventReader, math::{Vec3, curve::EaseFunction}, ecs::world::World, ecs::system::Query, ecs::entity::Entity, ecs::query::With}; + /// # use bevy::{ecs::event::EventReader, math::{Vec3, curve::EaseFunction}, ecs::world::World, ecs::system::{In, Query}, ecs::entity::Entity, ecs::query::With}; /// # use std::time::Duration; /// let mut world = World::new(); /// let test_system_system_id = world.register_system(test_system); @@ -607,16 +608,17 @@ impl Tween { /// ) /// .with_completed_system(test_system_system_id); /// - /// fn test_system(query: Query) { - /// for entity in query.iter() { - /// println!("Found an entity!"); + /// fn test_system(In(entity): In, query: Query<&Transform>) { + /// println!("Tween completed on entity {:?}", entity); + /// if let Ok(transform) = query.get(entity) { + /// println!("Its transform is {:?}", transform); /// } /// } /// ``` /// [`with_completed()`]: Tween::with_completed /// [`register_system()`]: bevy::ecs::world::World::register_system #[must_use] - pub fn with_completed_system(mut self, system_id: SystemId) -> Self { + pub fn with_completed_system(mut self, system_id: SystemId) -> Self { self.system_id = Some(system_id); self } @@ -718,13 +720,14 @@ impl Tween { /// Enable running a one-shot system upon completion. /// /// If enabled, the tween will run a system via a provided [`SystemId`] when - /// the animation completes. This is similar to the - /// [`with_completed()`], but uses a system registered by - /// [`register_system()`] instead of a callback. + /// the animation completes. The system receives the [`Entity`] the animator + /// is attached to as its input. This is similar to [`with_completed()`], + /// but uses a system registered by [`register_system()`] instead of a + /// callback. /// /// [`with_completed()`]: Tween::with_completed /// [`register_system()`]: bevy::ecs::world::World::register_system - pub fn set_completed_system(&mut self, user_data: SystemId) { + pub fn set_completed_system(&mut self, user_data: SystemId) { self.system_id = Some(user_data); } @@ -806,7 +809,7 @@ impl Tweenable for Tween { cb(entity, self); } if let Some(system_id) = &self.system_id { - commands.run_system(*system_id); + commands.run_system_with_input(*system_id, entity); } } @@ -1072,7 +1075,7 @@ pub struct Delay { timer: Timer, on_completed: Option>>>, event_data: Option, - system_id: Option, + system_id: Option>, } impl Delay { @@ -1164,7 +1167,7 @@ impl Delay { /// [`with_completed_event()`]: Delay::with_completed_event pub fn with_completed(mut self, callback: C) -> Self where - C: Fn(Entity, &Self) + Send + Sync + 'static, + C: Fn(Entity, &Self) + Send .+ Sync + 'static, { self.on_completed = Some(Box::new(callback)); self @@ -1173,15 +1176,16 @@ impl Delay { /// Enable running a one-shot system upon completion. /// /// If enabled, the tween will run a system via a provided [`SystemId`] when - /// the animation completes. This is similar to the - /// [`with_completed()`], but uses a system registered by - /// [`register_system()`] instead. + /// the animation completes. The system receives the [`Entity`] the animator + /// is attached to as its input. This is similar to [`with_completed()`], + /// but uses a system registered by [`register_system()`] instead of a + /// callback. /// /// # Example /// /// ``` /// # use bevy_tweening::{lens::*, *}; - /// # use bevy::{ecs::event::EventReader, math::{Vec3, curve::EaseFunction}, ecs::world::World, ecs::system::Query, ecs::entity::Entity}; + /// # use bevy::{ecs::event::EventReader, math::{Vec3, curve::EaseFunction}, ecs::world::World, ecs::system::{In, Query}, ecs::entity::Entity}; /// # use std::time::Duration; /// let mut world = World::new(); /// let test_system_system_id = world.register_system(test_system); @@ -1196,9 +1200,10 @@ impl Delay { /// ) /// .with_completed_system(test_system_system_id); /// - /// fn test_system(query: Query) { - /// for entity in query.iter() { - /// println!("Found an Entity!"); + /// fn test_system(In(entity): In, query: Query<&Transform>) { + /// println!("Tween completed on entity {:?}", entity); + /// if let Ok(transform) = query.get(entity) { + /// println!("Its transform is {:?}", transform); /// } /// } /// ``` @@ -1206,7 +1211,7 @@ impl Delay { /// [`with_completed()`]: Delay::with_completed /// [`register_system()`]: bevy::ecs::world::World::register_system #[must_use] - pub fn with_completed_system(mut self, system_id: SystemId) -> Self { + pub fn with_completed_system(mut self, system_id: SystemId) -> Self { self.system_id = Some(system_id); self } @@ -1274,16 +1279,17 @@ impl Delay { /// Enable running a one-shot system upon completion. /// /// If enabled, the tween will run a system via a provided [`SystemId`] when - /// the animation completes. This is similar to the - /// [`with_completed()`], but uses a system registered by - /// [`register_system()`] instead of a callback. + /// the animation completes. The system receives the [`Entity`] the animator + /// is attached to as its input. This is similar to [`with_completed()`], + /// but uses a system registered by [`register_system()`] instead of a + /// callback. /// /// See [`with_completed_system()`] for details. /// /// [`with_completed()`]: Delay::with_completed /// [`with_completed_system()`]: Delay::with_completed_system /// [`register_system()`]: bevy::ecs::world::World::register_system - pub fn set_completed_system(&mut self, system_id: SystemId) { + pub fn set_completed_system(&mut self, system_id: SystemId) { self.system_id = Some(system_id); } @@ -1350,7 +1356,7 @@ impl Tweenable for Delay { cb(entity, self); } if let Some(system_id) = &self.system_id { - commands.run_system(*system_id); + commands.run_system_with_input(*system_id, entity); } } @@ -1396,7 +1402,7 @@ mod tests { } /// Utility to create a test environment to tick a tween. - fn make_test_env() -> (World, Entity, SystemId) { + fn make_test_env() -> (World, Entity, SystemId) { let mut world = World::new(); world.init_resource::>(); let entity = world.spawn(Transform::default()).id(); @@ -1405,7 +1411,7 @@ mod tests { } /// one-shot system to be used for testing - fn oneshot_test() {} + fn oneshot_test(In(_entity): In) {} /// Manually tick a test tweenable targeting a component. fn manual_tick_component>(