Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.14 #129

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
10 changes: 7 additions & 3 deletions benchmarks/benches/lens.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
55 changes: 35 additions & 20 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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,
};

Expand All @@ -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(),
Expand All @@ -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]
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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));
}
}
14 changes: 8 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/tweenable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ impl<T> Tween<T> {
/// # 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(
/// // [...]
Expand Down Expand Up @@ -720,7 +720,7 @@ impl<T> Tween<T> {
/// 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);
Expand Down Expand Up @@ -1341,11 +1341,7 @@ impl<T> Tweenable<T> for Delay<T> {
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::*};
Expand Down
Loading