From 1e46e67938ef21cfd3b80a9bd7f9e3de1edd425c Mon Sep 17 00:00:00 2001 From: Seldom <38388947+Seldom-SE@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:52:53 -0700 Subject: [PATCH] Bevy 0.14 --- Cargo.toml | 6 ++--- benchmarks/Cargo.toml | 2 +- benchmarks/benches/lens.rs | 10 ++++--- src/lens.rs | 55 ++++++++++++++++++++++++-------------- src/lib.rs | 14 +++++----- src/tweenable.rs | 10 +++---- 6 files changed, 57 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c4e340..ecda754 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,10 @@ bevy_text = ["bevy/bevy_text", "bevy/bevy_render", "bevy/bevy_sprite"] [dependencies] interpolation = "0.3" -bevy = { version = "0.13", default-features = false } +bevy = { version = "0.14", default-features = false } -[dev-dependencies] -bevy-inspector-egui = "0.23" +# [dev-dependencies] +# bevy-inspector-egui = { git = "https://github.com/kristoff3r/bevy-inspector-egui", rev = "08181d8" } [[example]] name = "menu" diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 9cb5194..cf0d9f6 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -18,7 +18,7 @@ criterion = { version = "0.5", features = ["html_reports"] } bevy_tweening = { path = "../" } [dependencies.bevy] -version = "0.13" +version = "0.14" 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 6e0fb98..edd1f49 100644 --- a/benchmarks/benches/lens.rs +++ b/benchmarks/benches/lens.rs @@ -1,14 +1,18 @@ #[macro_use] extern crate criterion; -use bevy::{ecs::component::Tick, prelude::*}; +use bevy::{ + color::palettes::css::{BLUE, RED}, + ecs::component::Tick, + prelude::*, +}; use bevy_tweening::{lens::*, ComponentTarget}; use criterion::{black_box, Criterion}; fn text_color_lens(c: &mut Criterion) { let mut lens = TextColorLens { - start: Color::RED, - end: Color::BLUE, + start: RED.into(), + end: BLUE.into(), section: 0, }; let mut text = Text::from_section( diff --git a/src/lens.rs b/src/lens.rs index 227d94e..2718c65 100644 --- a/src/lens.rs +++ b/src/lens.rs @@ -409,9 +409,11 @@ mod tests { #[cfg(feature = "bevy_text")] #[test] fn text_color() { + use bevy::color::palettes::css::{BLUE, RED}; + let mut lens = TextColorLens { - start: Color::RED, - end: Color::BLUE, + start: RED.into(), + end: BLUE.into(), section: 0, }; let mut text = Text::from_section("", default()); @@ -429,7 +431,7 @@ mod tests { lens.lerp(&mut target, 0.); } - assert_eq!(text.sections[0].style.color, Color::RED); + assert_eq!(text.sections[0].style.color, RED.into()); { let mut added = Tick::new(0); @@ -444,7 +446,7 @@ mod tests { lens.lerp(&mut target, 1.); } - assert_eq!(text.sections[0].style.color, Color::BLUE); + assert_eq!(text.sections[0].style.color, BLUE.into()); { let mut added = Tick::new(0); @@ -459,11 +461,14 @@ mod tests { lens.lerp(&mut target, 0.3); } - assert_eq!(text.sections[0].style.color, Color::rgba(0.7, 0., 0.3, 1.0)); + assert_eq!( + text.sections[0].style.color, + Color::srgba(0.7, 0., 0.3, 1.0) + ); let mut lens_section1 = TextColorLens { - start: Color::RED, - end: Color::BLUE, + start: RED.into(), + end: BLUE.into(), section: 1, }; @@ -481,7 +486,10 @@ mod tests { lens_section1.lerp(&mut target, 1.); } // Should not have changed because the lens targets section 1 - assert_eq!(text.sections[0].style.color, Color::rgba(0.7, 0., 0.3, 1.0)); + assert_eq!( + text.sections[0].style.color, + Color::srgba(0.7, 0., 0.3, 1.0) + ); text.sections.push(TextSection { value: "".to_string(), @@ -501,7 +509,10 @@ mod tests { lens_section1.lerp(&mut target, 0.3); } - assert_eq!(text.sections[1].style.color, Color::rgba(0.7, 0., 0.3, 1.0)); + assert_eq!( + text.sections[1].style.color, + Color::srgba(0.7, 0., 0.3, 1.0) + ); } #[test] @@ -995,9 +1006,11 @@ mod tests { #[cfg(all(feature = "bevy_sprite", feature = "bevy_asset"))] #[test] fn colormaterial_color() { + use bevy::color::palettes::css::{BLUE, RED}; + let mut lens = ColorMaterialColorLens { - start: Color::RED, - end: Color::BLUE, + start: RED.into(), + end: BLUE.into(), }; let mut assets = Assets::default(); let handle = assets.add(ColorMaterial { @@ -1019,7 +1032,7 @@ mod tests { lens.lerp(&mut target, 0.); } - assert_eq!(assets.get(handle.clone()).unwrap().color, Color::RED); + assert_eq!(assets.get(handle.id()).unwrap().color, RED.into()); { let mut added = Tick::new(0); @@ -1035,7 +1048,7 @@ mod tests { lens.lerp(&mut target, 1.); } - assert_eq!(assets.get(handle.clone()).unwrap().color, Color::BLUE); + assert_eq!(assets.get(handle.id()).unwrap().color, BLUE.into()); { let mut added = Tick::new(0); @@ -1052,17 +1065,19 @@ mod tests { lens.lerp(&mut target, 0.3); } assert_eq!( - assets.get(handle).unwrap().color, - Color::rgba(0.7, 0., 0.3, 1.0) + assets.get(handle.id()).unwrap().color, + Color::srgba(0.7, 0., 0.3, 1.0) ); } #[cfg(feature = "bevy_sprite")] #[test] fn sprite_color() { + use bevy::color::palettes::css::{BLUE, RED}; + let mut lens = SpriteColorLens { - start: Color::RED, - end: Color::BLUE, + start: RED.into(), + end: BLUE.into(), }; let mut sprite = Sprite { color: Color::WHITE, @@ -1082,7 +1097,7 @@ mod tests { lens.lerp(&mut target, 0.); } - assert_eq!(sprite.color, Color::RED); + assert_eq!(sprite.color, RED.into()); { let mut added = Tick::new(0); @@ -1097,7 +1112,7 @@ mod tests { lens.lerp(&mut target, 1.); } - assert_eq!(sprite.color, Color::BLUE); + assert_eq!(sprite.color, BLUE.into()); { let mut added = Tick::new(0); @@ -1112,6 +1127,6 @@ mod tests { lens.lerp(&mut target, 0.3); } - assert_eq!(sprite.color, Color::rgba(0.7, 0., 0.3, 1.0)); + assert_eq!(sprite.color, Color::srgba(0.7, 0., 0.3, 1.0)); } } diff --git a/src/lib.rs b/src/lib.rs index aae1fc8..473795d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -585,11 +585,13 @@ trait ColorLerper { #[cfg(any(feature = "bevy_sprite", feature = "bevy_ui", feature = "bevy_text"))] 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) + let linear = self.to_linear(); + let target = target.to_linear(); + let r = linear.red.lerp(target.red, ratio); + let g = linear.green.lerp(target.green, ratio); + let b = linear.blue.lerp(target.blue, ratio); + let a = linear.alpha.lerp(target.alpha, ratio); + Color::linear_rgba(r, g, b, a) } } @@ -680,7 +682,7 @@ mod tests { l.lerp(&mut target, r); } - assert_approx_eq!(assets.get(handle.clone()).unwrap().value, r); + assert_approx_eq!(assets.get(handle.id()).unwrap().value, r); } } diff --git a/src/tweenable.rs b/src/tweenable.rs index de83b3d..c3b80d0 100644 --- a/src/tweenable.rs +++ b/src/tweenable.rs @@ -593,7 +593,7 @@ impl Tween { /// # use bevy_tweening::{lens::*, *}; /// # use bevy::{ecs::event::EventReader, math::Vec3, ecs::world::World, ecs::system::Query, ecs::entity::Entity, ecs::query::With}; /// # use std::time::Duration; - /// let mut world = World::new(); + /// let mut world = World::new(); /// let test_system_system_id = world.register_system(test_system); /// let tween = Tween::new( /// // [...] @@ -720,7 +720,7 @@ impl Tween { /// animation completes. This is similar to the [`with_completed()`], /// but uses a system registered by [`register_system()`] instead of a callback. /// - /// [`with_completed()`]: Tween::with_completed + /// [`with_completed()`]: Tween::with_completed /// [`register_system()`]: bevy::ecs::world::World::register_system pub fn set_completed_system(&mut self, user_data: SystemId) { self.system_id = Some(user_data); @@ -1341,11 +1341,7 @@ impl Tweenable for Delay { mod tests { use std::sync::{Arc, Mutex}; - use bevy::ecs::{ - component::Tick, - event::Events, - system::{CommandQueue, SystemState}, - }; + use bevy::ecs::{component::Tick, event::Events, system::SystemState, world::CommandQueue}; use super::*; use crate::{lens::*, test_utils::*};