use nightshade::prelude::*;
pub fn animate_position(
world: &mut World,
entity: Entity,
to: Vec3,
seconds: f32,
easing: EasingFunction,
) {
let Some(from) = world
.core
.get_local_transform(entity)
.map(|transform| transform.translation)
else {
return;
};
world.resources.tweens.active.retain(|tween| {
!(tween.entity == entity && matches!(tween.target, TweenTarget::Position { .. }))
});
world.resources.tweens.active.push(Tween {
entity,
target: TweenTarget::Position { from, to },
duration_seconds: seconds,
elapsed_seconds: 0.0,
easing,
});
}
pub fn animate_scale(
world: &mut World,
entity: Entity,
to: Vec3,
seconds: f32,
easing: EasingFunction,
) {
let Some(from) = world
.core
.get_local_transform(entity)
.map(|transform| transform.scale)
else {
return;
};
world.resources.tweens.active.retain(|tween| {
!(tween.entity == entity && matches!(tween.target, TweenTarget::Scale { .. }))
});
world.resources.tweens.active.push(Tween {
entity,
target: TweenTarget::Scale { from, to },
duration_seconds: seconds,
elapsed_seconds: 0.0,
easing,
});
}
pub fn animate_color(
world: &mut World,
entity: Entity,
to: [f32; 4],
seconds: f32,
easing: EasingFunction,
) {
let Some(from) = crate::appearance::owned_color(world, entity) else {
return;
};
world.resources.tweens.active.retain(|tween| {
!(tween.entity == entity && matches!(tween.target, TweenTarget::Color { .. }))
});
world.resources.tweens.active.push(Tween {
entity,
target: TweenTarget::Color { from, to },
duration_seconds: seconds,
elapsed_seconds: 0.0,
easing,
});
}
pub fn shake_camera(world: &mut World, strength: f32, seconds: f32) {
let shake = &mut world.resources.tweens.shake;
shake.strength = strength;
shake.duration_seconds = seconds;
shake.remaining_seconds = seconds;
}