From f59501a92bae12ae732dd2e26a6b1f869e3e4db9 Mon Sep 17 00:00:00 2001 From: Daniel Santana Date: Tue, 27 Feb 2024 20:47:06 +0000 Subject: [PATCH] Update to bevy 0.13 (#119) Co-authored-by: Jerome Humbert --- Cargo.toml | 6 +++--- benchmarks/Cargo.toml | 4 ++-- benchmarks/benches/lens.rs | 2 +- src/lens.rs | 32 ++++++++++++++++---------------- src/lib.rs | 30 +++++++++++++++++++++--------- src/plugin.rs | 6 +----- src/tweenable.rs | 14 ++++---------- 7 files changed, 48 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 35d25e5..acc4c2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index b53cacc..efa815a 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -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"] diff --git a/benchmarks/benches/lens.rs b/benchmarks/benches/lens.rs index 1972252..130c460 100644 --- a/benchmarks/benches/lens.rs +++ b/benchmarks/benches/lens.rs @@ -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))) }); diff --git a/src/lens.rs b/src/lens.rs index a48a0c4..0afd1fc 100644 --- a/src/lens.rs +++ b/src/lens.rs @@ -93,14 +93,14 @@ pub struct TextColorLens { #[cfg(feature = "bevy_text")] impl Lens for TextColorLens { fn lerp(&mut self, target: &mut Text, ratio: f32) { + use crate::ColorLerper as _; + // Note: Add for Color affects alpha, but not Mul. 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; } } } @@ -335,10 +335,10 @@ pub struct UiBackgroundColorLens { #[cfg(feature = "bevy_ui")] impl Lens 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; } } @@ -358,12 +358,12 @@ pub struct ColorMaterialColorLens { #[cfg(feature = "bevy_sprite")] impl Lens for ColorMaterialColorLens { fn lerp(&mut self, target: &mut ColorMaterial, ratio: f32) { + use crate::ColorLerper as _; + // Note: Add for Color affects alpha, but not Mul. 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; } } @@ -383,12 +383,12 @@ pub struct SpriteColorLens { #[cfg(feature = "bevy_sprite")] impl Lens for SpriteColorLens { fn lerp(&mut self, target: &mut Sprite, ratio: f32) { + use crate::ColorLerper as _; + // Note: Add for Color affects alpha, but not Mul. 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; } } diff --git a/src/lib.rs b/src/lib.rs index 6aeb71f..3b4f1c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -539,11 +537,26 @@ impl AssetAnimator { 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::*; @@ -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 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); } } @@ -583,7 +595,7 @@ mod tests { #[cfg(feature = "bevy_asset")] impl Lens 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); } } diff --git a/src/plugin.rs b/src/plugin.rs index f31def6..b8a0db8 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -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}; @@ -140,8 +138,6 @@ pub fn asset_animator_system( #[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 diff --git a/src/tweenable.rs b/src/tweenable.rs index 45476e1..673e1ff 100644 --- a/src/tweenable.rs +++ b/src/tweenable.rs @@ -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. @@ -486,7 +483,7 @@ impl Tween { /// .with_completed_event(42); /// /// fn my_system(mut reader: EventReader) { - /// for ev in reader.iter() { + /// for ev in reader.read() { /// assert_eq!(ev.user_data, 42); /// println!("Entity {:?} raised TweenCompleted!", ev.entity); /// } @@ -991,7 +988,7 @@ impl Delay { /// .with_completed_event(42); /// /// fn my_system(mut reader: EventReader) { - /// for ev in reader.iter() { + /// for ev in reader.read() { /// assert_eq!(ev.user_data, 42); /// println!("Entity {:?} raised TweenCompleted!", ev.entity); /// } @@ -1162,12 +1159,9 @@ impl Tweenable for Delay { #[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::*};