vleue / bevy_easings

Bevy plugin for easings and simple animations
181 stars 28 forks source link

Chain easing from vector #36

Open soanvig opened 5 months ago

soanvig commented 5 months ago

Hey! I would like to start with BIG THANKS for creating a library that is great of use to me as a Bevy newbie.

I have dynamically generated vector of animations to perform (interpolated movement on the grid). It is almost impossible (more on that later) to convert that vector to chain of animations.

Normally one would use fold: vector.iter().fold(component, |component, animation| component.ease_to(animation) but it doesn't work, because types change:

component -> Component
component.ease_to() -> EasingComponent<Component>
component.ease_to().ease_to() -> EasingChainComponent<Component>
component.ease_to().ease_to().ease_to() -> EasingChainComponent<Component>

The best workaround I found is to call .ease_to two times to stabilize type into EasingChainComponent, and then fold normally:

let animation_component = component
            .ease_to(
                component.clone(),
                EaseMethod::Linear,
                EasingType::Once {
                    duration: std::time::Duration::from_millis(0),
                },
            )
            .ease_to(
                component.clone(),
                EaseMethod::Linear,
                EasingType::Once {
                    duration: std::time::Duration::from_millis(0),
                },
            );

        let animation_component =
            interpolation
                .iter()
                .fold(animation_component, |component, interpolation_item| {
                    component.ease_to(
                        <actual easing using interpolation_item>
                    )
                });

I think it would be interesting to have some way to approach that in non-hacky way. I'm newbie, so I really cannot suggest anything unfortunately.