Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Multirious committed Mar 12, 2024
1 parent 57e608e commit c9b2211
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 70 deletions.
6 changes: 4 additions & 2 deletions .helix/languages.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[language-server.rust-analyzer]
config = { checkOnSave = { command = "clippy" }, cargo = { allFeatures = true }}
[language-server.rust-analyzer.config]
checkOnSave = { command = "clippy" }
cargo = { allFeatures = true }
rustfmt = { extraArgs = [ "+nightly" ] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# `bevy_tween`

WIP Flexible tweening plugin for Bevy.
Flexible tweening plugin for Bevy.

Credits:
- [`bevy_tweening`](https://github.com/djeedai/bevy_tweening)
Expand Down
3 changes: 2 additions & 1 deletion examples/demo_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use bevy_tween::prelude::*;
mod utils;

mod my_interpolate {
use std::sync::OnceLock;

use bevy::prelude::*;
use bevy_tween::prelude::*;
use std::sync::OnceLock;

pub struct JustTranslateTo {
pub start: OnceLock<Vec3>,
Expand Down
1 change: 0 additions & 1 deletion examples/demo_follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::f32::consts::TAU;

use bevy::prelude::*;
use bevy_inspector_egui::quick::ResourceInspectorPlugin;

use bevy_tween::prelude::*;

fn main() {
Expand Down
3 changes: 2 additions & 1 deletion examples/simple_tween.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use bevy::prelude::*;
use bevy_tween::prelude::*;
use std::time::Duration;

fn main() {
App::new()
Expand Down
3 changes: 2 additions & 1 deletion examples/simple_tween_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use bevy::prelude::*;
use bevy_tween::prelude::*;
use std::time::Duration;

fn main() {
App::new()
Expand Down
7 changes: 7 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
max_width = 80
# comment_width = 90
# wrap_comments = true
format_code_in_doc_comments = true
match_arm_leading_pipes = "Preserve"
reorder_impl_items = true
group_imports = "StdExternalCrate"
use_field_init_shorthand = true
1 change: 1 addition & 0 deletions src/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl<T> InterpolatorReflected for T where T: Interpolator + Reflect {}

impl<I: 'static> Interpolator for Box<dyn InterpolatorReflected<Item = I>> {
type Item = I;

fn interpolate(&self, item: &mut Self::Item, value: f32) {
(**self).interpolate(item, value);
}
Expand Down
28 changes: 11 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
//!
//! fn main() {
//! App::default()
//! .add_plugins((
//! DefaultPlugins,
//! DefaultTweenPlugins,
//! ))
//! .add_plugins((DefaultPlugins, DefaultTweenPlugins))
//! .run();
//! }
//! ```
Expand Down Expand Up @@ -118,7 +115,7 @@
//! ```no_run
#![doc = include_str!("../examples/simple_tween.rs")]
//! ```
//!
//!
//! [`Tween`]: tween::Tween
//! [`TweenDyn`]: tween::Tween
//! [`Interpolator`]: interpolate::Interpolator
Expand Down Expand Up @@ -150,24 +147,21 @@ pub mod prelude {

pub use crate::interpolate::{self, Interpolator};
pub use crate::interpolation::EaseFunction;
pub use crate::tween_timer::{Repeat, RepeatStyle, TweenTimerEnded};
pub use crate::BevyTweenRegisterSystems;
pub use crate::DefaultTweenPlugins;

#[cfg(feature = "span_tween")]
pub use crate::span_tween::{
BuildSpanTweens, SpanTweenBundle, SpanTweenPlayerBundle,
};
#[cfg(feature = "bevy_asset")]
pub use crate::tween::AssetTween;
pub use crate::tween::ComponentTween;
pub use crate::tween::ResourceTween;

#[cfg(feature = "bevy_asset")]
pub use crate::tween::AssetTweenDyn;
pub use crate::tween::ComponentTween;
pub use crate::tween::ComponentTweenDyn;
pub use crate::tween::ResourceTween;
pub use crate::tween::ResourceTweenDyn;

#[cfg(feature = "span_tween")]
pub use crate::span_tween::{
BuildSpanTweens, SpanTweenBundle, SpanTweenPlayerBundle,
};
pub use crate::tween_timer::{Repeat, RepeatStyle, TweenTimerEnded};
pub use crate::BevyTweenRegisterSystems;
pub use crate::DefaultTweenPlugins;
}

#[cfg(feature = "bevy_asset")]
Expand Down
107 changes: 63 additions & 44 deletions src/span_tween.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Module containing a tween player that process tweens with time span.
use bevy::{ecs::system::EntityCommands, prelude::*};
use std::{ops, time::Duration};

use bevy::{ecs::system::EntityCommands, prelude::*};

use crate::{
interpolation::Interpolation,
prelude::EaseFunction,
Expand Down Expand Up @@ -147,10 +148,12 @@ impl TweenTimeSpan {
(false, false) => unreachable!(),
}
}

/// Get the min time
pub fn min(&self) -> TimeBound {
self.min
}

/// Get the max time
pub fn max(&self) -> TimeBound {
self.max
Expand All @@ -165,6 +168,7 @@ impl Default for TweenTimeSpan {

impl TryFrom<ops::Range<Duration>> for TweenTimeSpan {
type Error = NewTweenTimeSpanError;

fn try_from(range: ops::Range<Duration>) -> Result<Self, Self::Error> {
TweenTimeSpan::new(
TimeBound::Inclusive(range.start),
Expand All @@ -174,6 +178,7 @@ impl TryFrom<ops::Range<Duration>> for TweenTimeSpan {
}
impl TryFrom<ops::RangeInclusive<Duration>> for TweenTimeSpan {
type Error = NewTweenTimeSpanError;

fn try_from(
range: ops::RangeInclusive<Duration>,
) -> Result<Self, Self::Error> {
Expand All @@ -186,6 +191,7 @@ impl TryFrom<ops::RangeInclusive<Duration>> for TweenTimeSpan {

impl TryFrom<ops::RangeTo<Duration>> for TweenTimeSpan {
type Error = NewTweenTimeSpanError;

fn try_from(range: ops::RangeTo<Duration>) -> Result<Self, Self::Error> {
TweenTimeSpan::new(
TimeBound::Inclusive(Duration::ZERO),
Expand All @@ -196,6 +202,7 @@ impl TryFrom<ops::RangeTo<Duration>> for TweenTimeSpan {

impl TryFrom<ops::RangeToInclusive<Duration>> for TweenTimeSpan {
type Error = NewTweenTimeSpanError;

fn try_from(
range: ops::RangeToInclusive<Duration>,
) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -224,12 +231,14 @@ impl SpanTweenPlayerBundle {
t.tween_timer.set_duration(duration);
t
}

/// [`SpanTweenPlayerBundle`] with the specified `paused` for the inner
/// [`TweenTimer`]
pub fn with_paused(mut self, paused: bool) -> Self {
self.tween_timer.set_paused(paused);
self
}

// pub fn with_elasped(mut self, elasped: Duration) -> Self {
// self.tween_player.set_elasped(elasped);
// self
Expand All @@ -247,6 +256,7 @@ impl SpanTweenPlayerBundle {
self.tween_timer.set_repeat(Some(repeat));
self
}

/// [`SpanTweenPlayerBundle`] with the specified `repeat_style`
/// setting the inner [`TweenTimer`]'s repeat_style to Some
pub fn with_repeat_style(
Expand All @@ -256,12 +266,14 @@ impl SpanTweenPlayerBundle {
self.tween_timer.set_repeat_style(Some(repeat_style));
self
}

/// [`SpanTweenPlayerBundle`] with without repeat,
/// setting the inner [`TweenTimer`]'s repeat to None.
pub fn without_repeat(mut self) -> Self {
self.tween_timer.set_repeat(None);
self
}

/// [`SpanTweenPlayerBundle`] with without repeat_style
/// setting the inner [`TweenTimer`]'s repeat_style to None.
pub fn without_repeat_style(mut self) -> Self {
Expand Down Expand Up @@ -313,9 +325,11 @@ pub fn span_tween_player_system(
>,
mut q_tween: Query<(&mut TweenState, &TweenTimeSpan)>,
) {
use crate::tween_timer::RepeatStyle::*;
use AnimationDirection::*;
use DurationQuotient::*;

use crate::tween_timer::RepeatStyle::*;

q_tween_span_player
.iter()
.for_each(|(player_entity, timer, children)| {
Expand Down Expand Up @@ -362,61 +376,66 @@ pub fn span_tween_player_system(
) {
(_, Inside, Inside, None) => Some(tween_elasped),
// -------------------------------------------------------
(Forward, Before, Inside, None)
| (Forward, Inside, After, None)
| (Forward, Before, After, None)
| (Forward, Before, Inside, None)
| (Forward, Inside, After, None)
| (Forward, Before, After, None)
=> Some(tween_elasped),

// -------------------------------------------------------
(Backward, After, Inside, None)
| (Backward, Inside, Before, None)
| (Backward, After, Before, None)
| (Backward, After, Inside, None)
| (Backward, Inside, Before, None)
| (Backward, After, Before, None)
=> Some(tween_elasped),

// --------------------------------------------------------
// don't remove these comments, may use for debugging in the future
(Forward, Before, Before, Some(WrapAround)) // 1&2 max
| (Forward, Inside, Before, Some(WrapAround)) // 1 max
| (Forward, Before, Before, Some(WrapAround)) // 1&2 max
| (Forward, Inside, Before, Some(WrapAround)) // 1 max
=> Some(tween_max),
(Forward, Before, Inside, Some(WrapAround)) // 2 now
| (Forward, Before, After, Some(WrapAround)) // 2 now, max
| (Forward, Inside, Inside, Some(WrapAround)) // 1&2 now
| (Forward, Inside, After, Some(WrapAround)) // 2 now, max
| (Forward, After, Inside, Some(WrapAround)) // 1 now
| (Forward, After, After, Some(WrapAround)) // 1&2 now, max
// | (Forward, After, Before, Some(WrapAround)) // 1
| (Forward, Before, Inside, Some(WrapAround)) // 2 now
| (Forward, Before, After, Some(WrapAround)) // 2 now, max
| (Forward, Inside, Inside, Some(WrapAround)) // 1&2 now
| (Forward, Inside, After, Some(WrapAround)) // 2 now, max
| (Forward, After, Inside, Some(WrapAround)) // 1 now
| (Forward, After, After, Some(WrapAround)) // 1&2 now, max
// | (Forward, After, Before, Some(WrapAround)) // 1
=> Some(tween_elasped),

// -------------------------------------------------------
(Backward, After, After, Some(WrapAround)) // 1&2 min
| (Backward, Inside, After, Some(WrapAround)) // 1 min
| (Backward, After, After, Some(WrapAround)) // 1&2 min
| (Backward, Inside, After, Some(WrapAround)) // 1 min
=> Some(tween_min),
(Backward, Before, Before, Some(WrapAround)) // 1&2 now, min
| (Backward, Before, Inside, Some(WrapAround)) // 1 now
| (Backward, Inside, Before, Some(WrapAround)) // 2 now, min
| (Backward, Inside, Inside, Some(WrapAround)) // 1&2 now
| (Backward, After, Before, Some(WrapAround)) // 2 now, min
| (Backward, After, Inside, Some(WrapAround)) // 2 now
// | (Backward, Before, After, Some(WrapAround)) // 1
| (Backward, Before, Before, Some(WrapAround)) // 1&2 now, min
| (Backward, Before, Inside, Some(WrapAround)) // 1 now
| (Backward, Inside, Before, Some(WrapAround)) // 2 now, min
| (Backward, Inside, Inside, Some(WrapAround)) // 1&2 now
| (Backward, After, Before, Some(WrapAround)) // 2 now, min
| (Backward, After, Inside, Some(WrapAround)) // 2 now
// | (Backward, Before, After, Some(WrapAround)) // 1
=> Some(tween_elasped),

// -------------------------------------------------------
(Backward, Before, Before, Some(PingPong)) // 1&2 now, min
| (Backward, Before, Inside, Some(PingPong)) // 1 now
| (Backward, Before, After, Some(PingPong)) // 1 now, max
| (Backward, Inside, Before, Some(PingPong)) // 2 now, min
| (Backward, Inside, Inside, Some(PingPong)) // 1&2 now
| (Backward, Inside, After, Some(PingPong)) // 1 now, max
| (Backward, After, Before, Some(PingPong)) // 2 now, min
| (Backward, After, Inside, Some(PingPong)) // 2 now
| (Backward, Before, Before, Some(PingPong)) // 1&2 now, min
| (Backward, Before, Inside, Some(PingPong)) // 1 now
| (Backward, Before, After, Some(PingPong)) // 1 now, max
| (Backward, Inside, Before, Some(PingPong)) // 2 now, min
| (Backward, Inside, Inside, Some(PingPong)) // 1&2 now
| (Backward, Inside, After, Some(PingPong)) // 1 now, max
| (Backward, After, Before, Some(PingPong)) // 2 now, min
| (Backward, After, Inside, Some(PingPong)) // 2 now
// | (Backward, After, After, Some(PingPong)) // 1&2
=> Some(tween_elasped),
// | (Backward, After, After, Some(PingPong)) // 1&2

// -------------------------------------------------------
// | (Forward, Before, Before, Some(PingPong)) // 1&2
| (Forward, Before, Inside, Some(PingPong)) // 2 now
| (Forward, Before, After, Some(PingPong)) // 2 now, max
| (Forward, Inside, Before, Some(PingPong)) // 1 now, min
| (Forward, Inside, Inside, Some(PingPong)) // 1&2 now
| (Forward, Inside, After, Some(PingPong)) // 2 now, max
| (Forward, After, Before, Some(PingPong)) // 1 now, min
| (Forward, After, Inside, Some(PingPong)) // 1 now
| (Forward, After, After, Some(PingPong)) // 1&2 now, max
// | (Forward, Before, Before, Some(PingPong)) // 1&2
| (Forward, Before, Inside, Some(PingPong)) // 2 now
| (Forward, Before, After, Some(PingPong)) // 2 now, max
| (Forward, Inside, Before, Some(PingPong)) // 1 now, min
| (Forward, Inside, Inside, Some(PingPong)) // 1&2 now
| (Forward, Inside, After, Some(PingPong)) // 2 now, max
| (Forward, After, Before, Some(PingPong)) // 1 now, min
| (Forward, After, Inside, Some(PingPong)) // 1 now
| (Forward, After, After, Some(PingPong)) // 1&2 now, max
=> Some(tween_elasped),
_ => None,
};
Expand Down
6 changes: 5 additions & 1 deletion src/tween.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
//!
//! [`interpolate`]: crate::interpolate
use std::{any::type_name, marker::PhantomData, time::Duration};

use bevy::ecs::schedule::SystemConfigs;
use bevy::prelude::*;
use std::{any::type_name, marker::PhantomData, time::Duration};

use crate::interpolate::Interpolator;
use crate::tween_timer::AnimationDirection;
Expand Down Expand Up @@ -161,14 +162,17 @@ where
pub fn tween_player_entity() -> TargetComponent<C> {
TargetComponent::TweenPlayerEntity(PhantomData)
}

/// Target the parent of this tween's tween_player.
pub fn tween_player_parent() -> TargetComponent<C> {
TargetComponent::TweenPlayerParent(PhantomData)
}

/// Target this entity.
pub fn entity(entity: Entity) -> TargetComponent<C> {
TargetComponent::Entity(entity, PhantomData)
}

/// Target these entities.
pub fn entities<I>(entities: I) -> TargetComponent<C>
where
Expand Down
Loading

0 comments on commit c9b2211

Please sign in to comment.