Skip to content

Commit

Permalink
Update to bevy 0.13 (#119)
Browse files Browse the repository at this point in the history
Co-authored-by: Jerome Humbert <djeedai@gmail.com>
  • Loading branch information
dgsantana and djeedai authored Feb 27, 2024
1 parent 5e6214b commit f59501a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 46 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ bevy_ui = ["bevy/bevy_ui", "bevy/bevy_render"]
bevy_text = ["bevy/bevy_text", "bevy/bevy_render", "bevy/bevy_sprite"]

[dependencies]
interpolation = "0.2"
bevy = { version = "0.12", default-features = false }
interpolation = "0.3"
bevy = { version = "0.13", default-features = false }

[dev-dependencies]
bevy-inspector-egui = "0.21"
bevy-inspector-egui = "0.23"

[[example]]
name = "menu"
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ include = ["assets", "thirdparty"]
exclude = ["examples/*.gif"]

[dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports"] }
bevy_tweening = { path = "../" }

[dependencies.bevy]
version = "0.12"
version = "0.13"
default-features = false
features = ["bevy_render", "bevy_sprite", "bevy_text", "bevy_ui"]

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benches/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn text_color_lens(c: &mut Criterion) {
color: Color::WHITE,
},
)
.with_alignment(TextAlignment::Center);
.with_justify(JustifyText::Center);
c.bench_function("TextColorLens", |b| {
b.iter(|| lens.lerp(&mut text, black_box(0.3)))
});
Expand Down
32 changes: 16 additions & 16 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ pub struct TextColorLens {
#[cfg(feature = "bevy_text")]
impl Lens<Text> for TextColorLens {
fn lerp(&mut self, target: &mut Text, ratio: f32) {
use crate::ColorLerper as _;

// Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
// consistency.
let start: Vec4 = self.start.into();
let end: Vec4 = self.end.into();
let value = start.lerp(end, ratio);
let value = self.start.lerp(&self.end, ratio);

if let Some(section) = target.sections.get_mut(self.section) {
section.style.color = value.into();
section.style.color = value;
}
}
}
Expand Down Expand Up @@ -335,10 +335,10 @@ pub struct UiBackgroundColorLens {
#[cfg(feature = "bevy_ui")]
impl Lens<BackgroundColor> for UiBackgroundColorLens {
fn lerp(&mut self, target: &mut BackgroundColor, ratio: f32) {
let start: Vec4 = self.start.into();
let end: Vec4 = self.end.into();
let value = start.lerp(end, ratio);
target.0 = value.into();
use crate::ColorLerper as _;

let value = self.start.lerp(&self.end, ratio);
target.0 = value;
}
}

Expand All @@ -358,12 +358,12 @@ pub struct ColorMaterialColorLens {
#[cfg(feature = "bevy_sprite")]
impl Lens<ColorMaterial> for ColorMaterialColorLens {
fn lerp(&mut self, target: &mut ColorMaterial, ratio: f32) {
use crate::ColorLerper as _;

// Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
// consistency.
let start: Vec4 = self.start.into();
let end: Vec4 = self.end.into();
let value = start.lerp(end, ratio);
target.color = value.into();
let value = self.start.lerp(&self.end, ratio);
target.color = value;
}
}

Expand All @@ -383,12 +383,12 @@ pub struct SpriteColorLens {
#[cfg(feature = "bevy_sprite")]
impl Lens<Sprite> for SpriteColorLens {
fn lerp(&mut self, target: &mut Sprite, ratio: f32) {
use crate::ColorLerper as _;

// Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
// consistency.
let start: Vec4 = self.start.into();
let end: Vec4 = self.end.into();
let value = start.lerp(end, ratio);
target.color = value.into();
let value = self.start.lerp(&self.end, ratio);
target.color = value;
}
}

Expand Down
30 changes: 21 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@

use std::time::Duration;

#[cfg(feature = "bevy_asset")]
use bevy::asset::Asset;
use bevy::prelude::*;
use interpolation::Ease as IEase;
pub use interpolation::{EaseFunction, Lerp};
Expand Down Expand Up @@ -539,11 +537,26 @@ impl<T: Asset> AssetAnimator<T> {
animator_impl!();
}

/// Trait to interpolate between two values.
/// Needed for color.
#[allow(dead_code)]
trait ColorLerper {
fn lerp(&self, target: &Self, ratio: f32) -> Self;
}

#[allow(dead_code)]
impl ColorLerper for Color {
fn lerp(&self, target: &Color, ratio: f32) -> Color {
let r = self.r().lerp(target.r(), ratio);
let g = self.g().lerp(target.g(), ratio);
let b = self.b().lerp(target.b(), ratio);
let a = self.a().lerp(target.a(), ratio);
Color::rgba(r, g, b, a)
}
}

#[cfg(test)]
mod tests {
#[cfg(feature = "bevy_asset")]
use bevy::reflect::TypeUuid;

use super::*;
use crate::test_utils::*;

Expand All @@ -558,15 +571,14 @@ mod tests {
}

#[cfg(feature = "bevy_asset")]
#[derive(Asset, Debug, Default, Reflect, TypeUuid)]
#[uuid = "a33abc11-264e-4bbb-82e8-b87226bb4383"]
#[derive(Asset, Debug, Default, Reflect)]
struct DummyAsset {
value: f32,
}

impl Lens<DummyComponent> for DummyLens {
fn lerp(&mut self, target: &mut DummyComponent, ratio: f32) {
target.value = self.start.lerp(&self.end, &ratio);
target.value = self.start.lerp(self.end, ratio);
}
}

Expand All @@ -583,7 +595,7 @@ mod tests {
#[cfg(feature = "bevy_asset")]
impl Lens<DummyAsset> for DummyLens {
fn lerp(&mut self, target: &mut DummyAsset, ratio: f32) {
target.value = self.start.lerp(&self.end, &ratio);
target.value = self.start.lerp(self.end, ratio);
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[cfg(feature = "bevy_asset")]
use bevy::asset::Asset;
use bevy::{ecs::component::Component, prelude::*};
use bevy::prelude::*;

#[cfg(feature = "bevy_asset")]
use crate::{tweenable::AssetTarget, AssetAnimator};
Expand Down Expand Up @@ -140,8 +138,6 @@ pub fn asset_animator_system<T: Asset>(

#[cfg(test)]
mod tests {
use bevy::prelude::{Events, IntoSystem, System, Transform, World};

use crate::{lens::TransformPositionLens, *};

/// A simple isolated test environment with a [`World`] and a single
Expand Down
14 changes: 4 additions & 10 deletions src/tweenable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use std::{ops::DerefMut, time::Duration};

use bevy::prelude::*;

#[cfg(feature = "bevy_asset")]
use bevy::asset::{Asset, AssetId};

use crate::{EaseMethod, Lens, RepeatCount, RepeatStrategy, TweeningDirection};

/// The dynamic tweenable type.
Expand Down Expand Up @@ -486,7 +483,7 @@ impl<T> Tween<T> {
/// .with_completed_event(42);
///
/// fn my_system(mut reader: EventReader<TweenCompleted>) {
/// for ev in reader.iter() {
/// for ev in reader.read() {
/// assert_eq!(ev.user_data, 42);
/// println!("Entity {:?} raised TweenCompleted!", ev.entity);
/// }
Expand Down Expand Up @@ -991,7 +988,7 @@ impl<T> Delay<T> {
/// .with_completed_event(42);
///
/// fn my_system(mut reader: EventReader<TweenCompleted>) {
/// for ev in reader.iter() {
/// for ev in reader.read() {
/// assert_eq!(ev.user_data, 42);
/// println!("Entity {:?} raised TweenCompleted!", ev.entity);
/// }
Expand Down Expand Up @@ -1162,12 +1159,9 @@ impl<T> Tweenable<T> for Delay<T> {

#[cfg(test)]
mod tests {
use std::{
sync::{Arc, Mutex},
time::Duration,
};
use std::sync::{Arc, Mutex};

use bevy::ecs::{event::Events, system::SystemState};
use bevy::ecs::system::SystemState;

use super::*;
use crate::{lens::*, test_utils::*};
Expand Down

0 comments on commit f59501a

Please sign in to comment.