Skip to content
Snippets Groups Projects
tweenable.rs 71.9 KiB
Newer Older

        // rewind
        tween.rewind();
        assert_eq!(TweeningDirection::Forward, tween.direction());
        assert_eq!(0, tween.times_completed());
        assert_approx_eq!(tween.progress(), 0.);
        let transform = world.entity(entity).get::<Transform>().unwrap();
        assert!(transform.translation.abs_diff_eq(Vec3::splat(0.1), 1e-5)); // no-op, rewind doesn't apply Lens

        // 120% - mirror
        let state =
            manual_tick_component(Duration::from_millis(1200), &mut tween, &mut world, entity);
        assert_eq!(TweeningDirection::Backward, tween.direction());
        assert_eq!(TweenState::Active, state);
        assert_eq!(1, tween.times_completed());
        assert_approx_eq!(tween.progress(), 0.2);
        let transform = world.entity(entity).get::<Transform>().unwrap();
        assert!(transform.translation.abs_diff_eq(Vec3::splat(0.8), 1e-5));

        // rewind
        tween.rewind();
        assert_eq!(TweeningDirection::Forward, tween.direction()); // restored
        assert_eq!(0, tween.times_completed());
        assert_approx_eq!(tween.progress(), 0.);
        let transform = world.entity(entity).get::<Transform>().unwrap();
        assert!(transform.translation.abs_diff_eq(Vec3::splat(0.8), 1e-5)); // no-op, rewind doesn't apply Lens

        // 400% - done mirror (because Completed freezes the state)
        let state =
            manual_tick_component(Duration::from_millis(4000), &mut tween, &mut world, entity);
        assert_eq!(TweenState::Completed, state);
        assert_eq!(TweeningDirection::Backward, tween.direction()); // frozen from last loop
        assert_eq!(4, tween.times_completed());
        assert_approx_eq!(tween.progress(), 1.); // Completed
        let transform = world.entity(entity).get::<Transform>().unwrap();
        assert!(transform.translation.abs_diff_eq(Vec3::ZERO, 1e-5));

        // rewind
        tween.rewind();
        assert_eq!(TweeningDirection::Forward, tween.direction()); // restored
        assert_eq!(0, tween.times_completed());
        assert_approx_eq!(tween.progress(), 0.);
        let transform = world.entity(entity).get::<Transform>().unwrap();
        assert!(transform.translation.abs_diff_eq(Vec3::ZERO, 1e-5)); // no-op, rewind doesn't apply Lens
    }