Multirious / bevy_tween

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

Implementation overhaul #39

Open Multirious opened 1 month ago

Multirious commented 1 month ago
  1. Not flexible enough for curves

Problem: This crate is not flexible enough for any curve more than a single f32, forcing user to create a custom system that's not within the crate's framework, if anyone even attempted it. Solution: The solution is to change how interpolator is implemented. Don't store curve in an interpolator and make value generic.

From

struct Translation { ... }
impl Interpolator for Translation {
    type Item = Transform
    fn interpolate(&self, item: &mut Self::Item, value: f32) { ... }
}

To

struct Translation;
impl Set for Translation {
    type Item = Transform;
    type Value = f32;
    fn set(&self, item: &mut Self::Item, value: &Value) { ... }
}

Curve is now decoupled from interpolator and implementor should set the item with whatever it receive from the value argument. To reflect this change, interpolator should be renamed to Set which directly describe what it should do.

Change TweenInterpolationValue(f32) to CurveValue<V>(V) to support the new design.

The original curve will be in another component called AToB<V, C> { a: V, b: V, curve: C } with curve that returns value within [0, 1]

  1. Registering new tween using systems is convoluted

Problem: Users must extends this crate by registering systems directly to register new tween. I even add more trait just to smooth this up. It's also hard for this crate to make changes to systems without breaking changes. And system cannot access the App. Solution: Use a plugin. This causes a lot of code due to each systems needing its own plugin. I've avoided this in the early versions because of this reason, but after awhile I've realized the advantages of using plugin outweigh the boilerplate.

Some more changes... todo!()