Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Multirious committed Mar 28, 2024
1 parent 1786050 commit 176d33f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 28 deletions.
15 changes: 15 additions & 0 deletions src/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ impl<I: 'static> Interpolator for dyn Fn(&mut I, f32) + Send + Sync + 'static {
}

/// Default interpolators
///
/// Register type and systems for the following interpolators:
/// - [`Translation`]
/// - [`Rotation`]
/// - [`Scale`]
/// - [`AngleZ`]
/// - [`SpriteColor`] if `"bevy_sprite"` feature is enabled.
/// - [`ColorMaterial`] if `"bevy_sprite"` feature is enabled.
pub struct DefaultInterpolatorsPlugin;
impl Plugin for DefaultInterpolatorsPlugin {
fn build(&self, app: &mut App) {
Expand All @@ -249,6 +257,13 @@ impl Plugin for DefaultInterpolatorsPlugin {
}

/// Default dynamic interpolators
///
/// Register systems for the following:
/// - [`Transform`] component.
/// - [`Sprite`] component if `"bevy_sprite"` feature is enabled.
/// - [`ColorMaterial`] asset if `"bevy_sprite"` feature is enabled.
///
/// [`ColorMaterial`]: bevy::sprite::ColorMaterial
pub struct DefaultDynInterpolatorsPlugin;
impl Plugin for DefaultDynInterpolatorsPlugin {
fn build(&self, app: &mut App) {
Expand Down
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
//! [`TweenTimeSpan`]: span_tween::TweenTimeSpan
//! [`ComponentTween`]: tween::ComponentTween
//! [`ComponentTweenDyn`]: tween::ComponentTweenDyn

#![allow(clippy::needless_doctest_main)]
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
#![warn(missing_docs)]

Expand Down Expand Up @@ -176,6 +176,13 @@ pub use tween::resource_tween_system;
pub use tween::resource_tween_system_full;

/// Default plugins for using crate.
///
/// Plugins:
/// - [`TweenCorePlugin`]
/// - [`interpolate::DefaultInterpolatorsPlugin`]
/// - [`interpolate::DefaultDynInterpolatorsPlugin`]
/// - [`interpolation::EaseFunctionPlugin`]
/// - [`span_tween::SpanTweenPlugin`] if `"span_tween"` feature is enabled.
pub struct DefaultTweenPlugins;
impl PluginGroup for DefaultTweenPlugins {
fn build(self) -> bevy::app::PluginGroupBuilder {
Expand Down Expand Up @@ -226,25 +233,23 @@ impl Plugin for TweenCorePlugin {
}
}

/// Enum of SystemSet in this crate
/// Enum of SystemSet in this crate.
/// See [`TweenCorePlugin`] for default system configuration.
#[derive(Debug, SystemSet, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TweenSystemSet {
/// This set is for systems that responsible for ticking any
/// tweener such as the [`span_tween::tick_span_tweener_system`]
/// by this crate
/// tweener such as [`span_tween::tick_span_tweener_system`].
TickTweener,
/// This set is for systems that responsible for updating any
/// tweener such as the [`span_tween::span_tweener_system`]
/// by this crate
/// tweener such as [`span_tween::span_tweener_system`].
Tweener,
/// This set is for systems that responsible for updating any
/// [`tween::TweenInterpolationValue`] such as
/// [`interpolation::sample_interpolations_system`] by this crate.
/// [`interpolation::sample_interpolations_system`].
UpdateInterpolationValue,
/// This set is for systems that responsible for actually executing any
/// active tween and setting the value to its respective tweening item such
/// as these systems by this crate:
/// as these systems:
/// - [`tween::component_tween_system`]
/// - [`tween::resource_tween_system`]
/// - [`tween::asset_tween_system`]
Expand Down
33 changes: 16 additions & 17 deletions src/tween.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@
//! - [`TweenProgressed`]
//! - [`TweenInterpolationValue`]
//!
//! Built-in supported [`TweenTarget`]s are:
//! Built-in supported targets are:
//! - [`TargetComponent`]
//! - [`TargetResource`]
//! - [`TargetAsset`]
//!
//! See available interpolator in [`interpolate`].
//! See available interpolators in [`interpolate`].
//!
//! ## Registering systems
//!
//! You have to register some necessary systems for this plugin to work properly
//! with every custom type and interpolators
//! unless there's some system already registered by the [`DefaultTweenPlugins`].
//! In order for your custom interpolators to work. You have to register systems
//! to actually have something happening.
//! The [`DefaultTweenPlugins`] will already register some systems for you already to get started.
//! Check [`DefaultInterpolatorsPlugin`] or [`DefaultDynInterpolatorsPlugin`].
//!
//! This crate already contains some systems for tweening components, assets,
//! and resources.
//! This crate contains some systems with generic for tweening components, assets,
//! and resources, allowing you to quickly register your custom interpolators.
//!
//! Built-in systems:
//! Systems:
//! - [`component_tween_system()`], component tweening system
//! - [`resource_tween_system()`], resource tweening system
//! - [`asset_tween_system()`], asset tweening system
Expand Down Expand Up @@ -91,13 +92,12 @@
//! # }
//! ```
//!
//! There's 2 type of system you might want to register.
//! There's 2 kind of system you might want to register.
//!
//! ### Registering system for generic interpolator
//!
//! Generic interpolator means we're not using any dynamic dispatch.
//! We've to register this system for **every individual interpolator**.
//! (Unless already registered by the [`DefaultTweenPlugins`])
//!
//! ```no_run
//! # mod a { // had to put this module here for some reason. tf?
Expand Down Expand Up @@ -160,8 +160,7 @@
//!
//! Dynamic interpolator means we're using dynamic dispatch or trait object.
//! We don't have to register system for every interpolator, we only have to
//! register this system just for **every individual component**.
//! (Unless already registered by the [`DefaultTweenPlugins`])
//! register this system just for **every individual component/asset/resource**.
// ///! <div class="warning">
// ///! <a href="fn.component_dyn_tween_system.html"><code>component_dyn_tween_system</code></a> is type of dynamic
// ///! interpolator for <code>Box&lt;dyn Interpolator&gt;</code>.
Expand Down Expand Up @@ -229,9 +228,10 @@
//! [`BevyTweenRegisterSystems`]: crate::BevyTweenRegisterSystems
//! [`interpolate`]: crate::interpolate
//! [`DefaultTweenPlugins`]: crate::DefaultTweenPlugins
//! [`DefaultInterpolatorsPlugin`]: crate::interpolate::DefaultInterpolatorsPlugin
//! [`DefaultDynInterpolatorsPlugin`]: crate::interpolate::DefaultDynInterpolatorsPlugin

use bevy::prelude::*;
use std::{any::type_name, marker::PhantomData};

use crate::interpolate::Interpolator;

Expand Down Expand Up @@ -263,14 +263,13 @@ pub struct SkipTween;
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.
/// An assigned tweener will take care of it.
#[derive(Debug, Default, Clone, Copy, PartialEq, Component, Reflect)]
#[reflect(Component)]
pub struct TweenProgressed(pub f32);

/// Automatically managed by an [`Interpolation`] such as [`EaseFunction`] and
/// [`EaseClosure`] when a tween has the component `TweenState`.
/// [`EaseClosure`] when a tween has the component [`TweenProgressed`].
/// See [`sample_interpolations_system`]
///
/// [`sample_interpolations_system`]: crate::interpolation::sample_interpolations_system
Expand All @@ -281,7 +280,7 @@ pub struct TweenProgressed(pub f32);
#[reflect(Component)] // might want to use sparseset but i'm not sure yet
pub struct TweenInterpolationValue(pub f32);

/// Containg [`TweenTarget`] and [`Interpolator`]
/// Containg `target` and `interpolator`
#[derive(
Debug, Default, Component, Clone, Copy, PartialEq, Eq, Hash, Reflect,
)]
Expand Down
45 changes: 42 additions & 3 deletions src/tween/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,45 @@ pub fn component_tween_system_full<C, I>(
component_tween_system(q_tweener, q_tween, q_component);
}

/// Tween any [`Tween`] with the [`Interpolator`] that [`TargetComponent`] with
/// Apply any [`Tween`] with the [`Interpolator`] that [`TargetComponent`] with
/// value provided by [`TweenInterpolationValue`] component.
///
/// The system uses generic for you to quickly make your interpolators work.
///
/// ```no_run
/// use bevy::prelude::*;
/// use bevy_tween::prelude::*;
///
/// #[derive(Component)]
/// struct Size(f32);
///
/// struct InterpolateSize {
/// start: f32,
/// end: f32,
/// }
///
/// impl Interpolator for InterpolateSize {
/// type Item = Size;
///
/// fn interpolate(&self, item: &mut Self::Item, value: f32) {
/// item.0 = self.start.lerp(self.end, value);
/// }
/// }
///
/// fn main() {
/// let mut app = App::new();
///
/// // Generic interpolator:
/// app.add_tween_systems(
/// bevy_tween::component_tween_system::<InterpolateSize>,
/// );
///
/// // Dynamic interpolator:
/// app.add_tween_systems(
/// bevy_tween::component_tween_system::<BoxedInterpolator<Size>>,
/// );
/// }
/// ```
#[allow(clippy::type_complexity)]
pub fn component_tween_system<I>(
q_tweener: Query<(Option<&Parent>, Has<TweenerMarker>)>,
Expand Down Expand Up @@ -128,7 +165,8 @@ pub fn resource_tween_system_full<R, I>(
resource_tween_system(q_tween, resource);
}

/// System alias for [`resource_tween_system_full`] that uses generic [`Interpolator`]..
/// Apply any [`Tween`] with the [`Interpolator`] that [`TargetResource`] with
/// value provided by [`TweenInterpolationValue`] component.
#[allow(clippy::type_complexity)]
pub fn resource_tween_system<I>(
q_tween: Query<
Expand Down Expand Up @@ -182,7 +220,8 @@ pub fn asset_tween_system_full<A, I>(
asset_tween_system(q_tween, asset);
}

/// System alias for [`asset_tween_system_full`] that uses generic [`Interpolator`].
/// Apply any [`Tween`] with the [`Interpolator`] that [`TargetAsset`] with
/// value provided by [`TweenInterpolationValue`] component.
#[cfg(feature = "bevy_asset")]
#[allow(clippy::type_complexity)]
pub fn asset_tween_system<I>(
Expand Down

0 comments on commit 176d33f

Please sign in to comment.