Multirious / bevy_tween

Flexible tweening plugin library for Bevy.
Apache License 2.0
87 stars 2 forks source link

Adding custom `AnimationBuilder` helper methods #23

Closed musjj closed 2 months ago

musjj commented 2 months ago

I'm trying to add my own helper method for AnimationBuilder to support this use case: https://github.com/Multirious/bevy_tween/issues/13

But the problem is that all the struct fields are private:

https://github.com/Multirious/bevy_tween/blob/417c173df1a73f4d103665e90fcfd60b875f720d/src/combinator.rs#L259-L263

Would it be reasonable to make those fields public?

Multirious commented 2 months ago

It's currently private to minimize future breaking changes as I assume they won't be stable. I guess it would be fine for now with getter or setter functions. What field needed to be public and does it requires mutability? Could this also be solved by wrapping this struct to a new struct with new extension trait?

musjj commented 2 months ago

For the specific method I'm trying to implement, I'd need mutable access to EntityCommands so that I can add additional components to the entity. The method would need to be able to add the SkipTweener component, a custom component to store the previous tween entity and also call the set_paused method.

I don't think a wrapper struct would let me access those fields though.

Multirious commented 2 months ago

Oh you can access EntityCommands before calling .animation. .insert* will also returns EntityCommands. You can also use .paused method on AnimationBuilder. Would this work?

musjj commented 2 months ago

Yeah, but what I'm hoping is that I can do all that in a single method. Something like .animation().insert(/* ... */).after(/* entity */) would be super clean.

Multirious commented 2 months ago

Hmm, having .after method after .insert probably wouldn't work since .insert* method will insert the TimeRunner automatically and TimeRunner won't be accessible after. I'm happy to allow access on EntityCommands in any case, seems like a good thing to have.

musjj commented 2 months ago

Oh, yeah you're right, the .after would have to be done before .insert right?

Multirious commented 2 months ago

Alright, I've pushed 63437d6. I've added getters to the inner TimeRunner and EntityCommands.

Multirious commented 2 months ago

Oops wait I think the method should return &Option<TimeRunner> not Option<&TimeRunner> Edit: 2f334b4

musjj commented 2 months ago

Thank you! I'll experiment with it a bit before closing the issue.

musjj commented 2 months ago

Ok, I think it's working pretty well. Thanks again!