Skip to content

Commit

Permalink
Add SkipTween and SkipTweener
Browse files Browse the repository at this point in the history
  • Loading branch information
Multirious committed Mar 26, 2024
1 parent 0bb4812 commit d667f6e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/span_tween.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use tween_timer::{Repeat, RepeatStyle};
use crate::{
interpolation::Interpolation,
prelude::EaseFunction,
tween::{TweenProgressed, TweenerMarker},
tween::{SkipTweener, TweenProgressed, TweenerMarker},
tween_timer::{self, AnimationDirection, TickResult, TweenTimer},
};

Expand Down Expand Up @@ -625,8 +625,11 @@ pub fn tick_span_tweener_system(
/// by its span tweener then will call `collaspe_elasped` on the timer.
pub fn span_tweener_system(
mut commands: Commands,
q_other_tweener: Query<(), With<SpanTweener>>,
mut q_span_tweener: Query<(Entity, &mut SpanTweener, Option<&Children>)>,
q_other_tweener: Query<(), With<TweenerMarker>>,
mut q_span_tweener: Query<
(Entity, &mut SpanTweener, Option<&Children>),
Without<SkipTweener>,
>,
mut q_tween: Query<(Option<&mut TweenProgressed>, &TweenTimeSpan)>,
) {
use AnimationDirection::*;
Expand All @@ -637,9 +640,6 @@ pub fn span_tweener_system(
q_span_tweener.iter_mut().for_each(
|(tweener_entity, mut tweener, children)| {
let timer = &tweener.timer;
if timer.paused {
return;
}

if timer.is_completed() {
return;
Expand Down
8 changes: 8 additions & 0 deletions src/tween.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ pub use systems::{
resource_tween_system_full,
};

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Component, Reflect)]
#[reflect(Component)]
pub struct SkipTween;

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Component, Reflect)]
#[reflect(Component)]
pub struct SkipTweener;

/// [`TweenProgressed`] should be automatically managed by a tweener.
/// User just have to add this component to a tween entity and an assigned
/// tweener will take care of it.
Expand Down
51 changes: 34 additions & 17 deletions src/tween/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ use bevy::ecs::schedule::SystemConfigs;
)]
pub fn component_tween_system_full<C, I>(
q_tweener: Query<(Option<&Parent>, Has<TweenerMarker>)>,
q_tween: Query<(
Entity,
&Tween<TargetComponent<C>, I>,
&TweenInterpolationValue,
)>,
q_tween: Query<
(
Entity,
&Tween<TargetComponent<C>, I>,
&TweenInterpolationValue,
),
Without<SkipTween>,
>,
q_component: Query<&mut I::Item>,
) where
C: Component,
Expand All @@ -29,11 +32,14 @@ pub fn component_tween_system_full<C, I>(
#[allow(clippy::type_complexity)]
pub fn component_tween_system<I>(
q_tweener: Query<(Option<&Parent>, Has<TweenerMarker>)>,
q_tween: Query<(
Entity,
&Tween<TargetComponent<I::Item>, I>,
&TweenInterpolationValue,
)>,
q_tween: Query<
(
Entity,
&Tween<TargetComponent<I::Item>, I>,
&TweenInterpolationValue,
),
Without<SkipTween>,
>,
mut q_component: Query<&mut I::Item>,
) where
I: Interpolator + Send + Sync + 'static,
Expand Down Expand Up @@ -116,8 +122,12 @@ where
since = "0.3.0",
note = "Use `resource_tween_system` instead with less required generic"
)]
#[allow(clippy::type_complexity)]
pub fn resource_tween_system_full<R, I>(
q_tween: Query<(&Tween<TargetResource<R>, I>, &TweenInterpolationValue)>,
q_tween: Query<
(&Tween<TargetResource<R>, I>, &TweenInterpolationValue),
Without<SkipTween>,
>,
resource: Option<ResMut<I::Item>>,
) where
R: Resource,
Expand All @@ -129,10 +139,10 @@ pub fn resource_tween_system_full<R, I>(
/// System alias for [`resource_tween_system_full`] that uses generic [`Interpolator`]..
#[allow(clippy::type_complexity)]
pub fn resource_tween_system<I>(
q_tween: Query<(
&Tween<TargetResource<I::Item>, I>,
&TweenInterpolationValue,
)>,
q_tween: Query<
(&Tween<TargetResource<I::Item>, I>, &TweenInterpolationValue),
Without<SkipTween>,
>,
resource: Option<ResMut<I::Item>>,
) where
I: Interpolator,
Expand Down Expand Up @@ -166,8 +176,12 @@ where
since = "0.3.0",
note = "Use `asset_tween_system` instead with less required generic"
)]
#[allow(clippy::type_complexity)]
pub fn asset_tween_system_full<A, I>(
q_tween: Query<(&Tween<TargetAsset<A>, I>, &TweenInterpolationValue)>,
q_tween: Query<
(&Tween<TargetAsset<A>, I>, &TweenInterpolationValue),
Without<SkipTween>,
>,
asset: Option<ResMut<Assets<I::Item>>>,
) where
A: Asset,
Expand All @@ -180,7 +194,10 @@ pub fn asset_tween_system_full<A, I>(
#[cfg(feature = "bevy_asset")]
#[allow(clippy::type_complexity)]
pub fn asset_tween_system<I>(
q_tween: Query<(&Tween<TargetAsset<I::Item>, I>, &TweenInterpolationValue)>,
q_tween: Query<
(&Tween<TargetAsset<I::Item>, I>, &TweenInterpolationValue),
Without<SkipTween>,
>,
asset: Option<ResMut<Assets<I::Item>>>,
) where
I: Interpolator,
Expand Down

0 comments on commit d667f6e

Please sign in to comment.