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

Updates for Bevy 0.13 #117

Closed
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bevy_text = ["bevy/bevy_text", "bevy/bevy_render", "bevy/bevy_sprite"]

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

[dev-dependencies]
bevy-inspector-egui = "0.21"
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
2 changes: 1 addition & 1 deletion examples/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
color: TEXT_COLOR,
},
)
.with_alignment(TextAlignment::Center),
.with_alignment(JustifyText::Center),
..default()
});
});
Expand Down
6 changes: 3 additions & 3 deletions examples/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
color: Color::BLUE,
};

let text_alignment = TextAlignment::Center;
let justify = JustifyText::Center;

// Text with the index of the active tween in the sequence
commands.spawn((
Expand All @@ -65,7 +65,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
style: text_style_red,
},
],
alignment: text_alignment,
justify,
..default()
},
transform: Transform::from_translation(Vec3::new(0., 40., 0.)),
Expand All @@ -88,7 +88,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
style: text_style_blue,
},
],
alignment: text_alignment,
justify,
..default()
},
transform: Transform::from_translation(Vec3::new(0., -40., 0.)),
Expand Down
22 changes: 22 additions & 0 deletions src/color_vec4_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use bevy::math::Vec4;
use bevy::render::color::Color;

pub(crate) trait ColorExt {
fn to_vec(&self) -> Vec4;
}

impl ColorExt for Color {
fn to_vec(&self) -> Vec4 {
Vec4::new(self.r(), self.g(), self.b(), self.a())
}
}

pub(crate) trait Vec4Ext {
fn to_color(&self) -> Color;
}

impl Vec4Ext for Vec4 {
fn to_color(&self) -> Color {
Color::rgba(self.x, self.y, self.z, self.w)
}
}
25 changes: 13 additions & 12 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//! [`Transform`]: https://docs.rs/bevy/0.12.0/bevy/transform/components/struct.Transform.html
//! [`Quat::slerp()`]: https://docs.rs/bevy/0.12.0/bevy/math/struct.Quat.html#method.slerp

use crate::color_vec4_ext::*;
use bevy::prelude::*;

/// A lens over a subset of a component.
Expand Down Expand Up @@ -95,12 +96,12 @@ impl Lens<Text> for TextColorLens {
fn lerp(&mut self, target: &mut Text, ratio: f32) {
// 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 start: Vec4 = self.start.to_vec();
let end: Vec4 = self.end.to_vec();
let value = start.lerp(end, ratio);

if let Some(section) = target.sections.get_mut(self.section) {
section.style.color = value.into();
section.style.color = value.to_color();
}
}
}
Expand Down Expand Up @@ -335,10 +336,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 start: Vec4 = self.start.to_vec();
let end: Vec4 = self.end.to_vec();
let value = start.lerp(end, ratio);
target.0 = value.into();
target.0 = value.to_color();
}
}

Expand All @@ -360,10 +361,10 @@ impl Lens<ColorMaterial> for ColorMaterialColorLens {
fn lerp(&mut self, target: &mut ColorMaterial, ratio: f32) {
// 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 start: Vec4 = self.start.to_vec();
let end: Vec4 = self.end.to_vec();
let value = start.lerp(end, ratio);
target.color = value.into();
target.color = value.to_color();
}
}

Expand All @@ -385,10 +386,10 @@ impl Lens<Sprite> for SpriteColorLens {
fn lerp(&mut self, target: &mut Sprite, ratio: f32) {
// 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 start: Vec4 = self.start.to_vec();
let end: Vec4 = self.end.to_vec();
let value = start.lerp(end, ratio);
target.color = value.into();
target.color = value.to_color();
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ pub use tweenable::{
TweenState, Tweenable,
};

mod color_vec4_ext;
pub mod lens;
mod plugin;
mod tweenable;
Expand Down Expand Up @@ -541,9 +542,6 @@ impl<T: Asset> AssetAnimator<T> {

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

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

Expand All @@ -558,15 +556,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 +580,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
4 changes: 2 additions & 2 deletions src/tweenable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,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 +991,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
Loading