From 17655468864cdd2e642873e133ae1e72ff20e518 Mon Sep 17 00:00:00 2001 From: Multirious Date: Wed, 10 Jul 2024 09:10:20 +0700 Subject: [PATCH 1/2] Public constructor for AnimationBuilder --- src/combinator.rs | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/combinator.rs b/src/combinator.rs index 894f2c6..dcce229 100644 --- a/src/combinator.rs +++ b/src/combinator.rs @@ -39,43 +39,26 @@ pub trait AnimationBuilderExt { impl<'a> AnimationBuilderExt for EntityCommands<'a> { /// Construct [`AnimationBuilder`] from [`EntityCommands`]. - /// Use this entity as the animation root. - /// Animations will be created as children this entity. + /// Use this entity as the animator. + /// Tweens will be spawned as children of this entity. fn animation(&mut self) -> AnimationBuilder<'_> { - AnimationBuilder { - entity_commands: self.reborrow(), - time_runner: None, - custom_length: None, - skipped: false, - } + AnimationBuilder::new(self.reborrow()) } } impl<'w, 's> AnimationBuilderExt for Commands<'w, 's> { /// Construct [`AnimationBuilder`] from [`Commands`]. - /// This will automatically spawn an entity for animation root. + /// This will automatically spawn an entity as the animator. fn animation(&mut self) -> AnimationBuilder<'_> { - let entity_commands = self.spawn_empty(); - AnimationBuilder { - entity_commands, - time_runner: None, - custom_length: None, - skipped: false, - } + AnimationBuilder::new(self.spawn_empty()) } } impl<'a> AnimationBuilderExt for ChildBuilder<'a> { /// Construct [`AnimationBuilder`] from [`ChildBuilder`]. - /// This will automatically spawn a child entity for animation root. + /// This will automatically spawn a child entity as the animator. fn animation(&mut self) -> AnimationBuilder<'_> { - let entity_commands = self.spawn_empty(); - AnimationBuilder { - entity_commands, - time_runner: None, - custom_length: None, - skipped: false, - } + AnimationBuilder::new(self.spawn_empty()) } } @@ -87,6 +70,16 @@ pub struct AnimationBuilder<'a> { skipped: bool, } impl<'a> AnimationBuilder<'a> { + /// Create new [`AnimationBuilder`] + pub fn new(entity_commands: EntityCommands<'a>) -> AnimationBuilder<'a> { + AnimationBuilder { + entity_commands, + time_runner: None, + custom_length: None, + skipped: false, + } + } + /// Get the inner [`EntityCommands`] pub fn entity_commands(&mut self) -> &mut EntityCommands<'a> { &mut self.entity_commands From 971ed1dc597268a8c0c766c1fb8cc0deed78e32f Mon Sep 17 00:00:00 2001 From: Multirious Date: Wed, 10 Jul 2024 09:11:40 +0700 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b651e24..5fd7817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Changes + +- Add public `new()` constructor for `AnimationBuilder` + ## v0.6.0 - 2024-7-7 ### Changes