From 50516760d56af91e519259fc3f2917ebc59a81df Mon Sep 17 00:00:00 2001 From: Liam Routt Date: Mon, 18 Mar 2024 15:03:16 +1100 Subject: [PATCH] Updates for Bevy 0.13 (#18) * Updates to Bevy 0.13 Updates to reach Bevy 0.13. All compiles, but examples all panic in a tweenable tick, for me. * Return patch Inadvertently removed the patch crate reference; returning it * Fixing format Fix to pacify cargo fmt --- Cargo.toml | 6 +++--- examples/custom_skip.rs | 8 ++++---- examples/layouts.rs | 14 +++++++------- examples/screens.rs | 8 ++++---- examples/simple.rs | 4 ++-- src/lens.rs | 14 ++++++-------- src/lib.rs | 18 ++++++++++++++++++ src/splash.rs | 2 +- 8 files changed, 45 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 751f07a..eb29b73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ opt-level = 1 opt-level = 3 [dev-dependencies] -bevy = { version = "0.12", default-features = false, features = [ +bevy = { version = "0.13", default-features = false, features = [ "multi-threaded", "bevy_asset", "bevy_winit", @@ -66,8 +66,8 @@ required-features = ["dev"] path = "./examples/simple.rs" [dependencies] -bevy = { version = "0.12", default-features = false } -bevy_tweening = "0.9" +bevy = { version = "0.13", default-features = false } +bevy_tweening = "0.10" [patch.crates-io] bevy_tweening = { git = "https://github.com/SergioRibera/bevy_tweening", branch = "infinite_mirrored" } diff --git a/examples/custom_skip.rs b/examples/custom_skip.rs index 8847785..ae1a46f 100644 --- a/examples/custom_skip.rs +++ b/examples/custom_skip.rs @@ -17,7 +17,7 @@ enum ScreenStates { fn main() { App::new() .add_plugins(DefaultPlugins) - .add_state::() + .init_state::() .add_plugins( SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu) .ignore_default_events() @@ -41,7 +41,7 @@ fn main() { }, ), ]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::WHITE, @@ -64,7 +64,7 @@ fn main() { ..default() }, ) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::WHITE, @@ -124,7 +124,7 @@ fn create_scene(mut cmd: Commands, assets: ResMut) { ..default() }, ) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), ..default() }, Animator::new( diff --git a/examples/layouts.rs b/examples/layouts.rs index 791513d..775f4cf 100644 --- a/examples/layouts.rs +++ b/examples/layouts.rs @@ -14,7 +14,7 @@ enum ScreenStates { fn main() { App::new() .add_plugins(DefaultPlugins) - .add_state::() + .init_state::() .add_plugins( SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu) .skipable() @@ -48,7 +48,7 @@ fn main() { }, ), ]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::SEA_GREEN, @@ -68,7 +68,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::WHITE, @@ -95,7 +95,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::YELLOW, @@ -115,7 +115,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::BLUE, @@ -135,7 +135,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::WHITE, @@ -155,7 +155,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::PURPLE, diff --git a/examples/screens.rs b/examples/screens.rs index 60e56c1..75a715f 100644 --- a/examples/screens.rs +++ b/examples/screens.rs @@ -14,7 +14,7 @@ enum ScreenStates { fn main() { App::new() .add_plugins(DefaultPlugins) - .add_state::() + .init_state::() .add_plugins( SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu) .add_screen(SplashScreen { @@ -46,7 +46,7 @@ fn main() { }, ), ]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::SEA_GREEN, @@ -70,7 +70,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::WHITE, @@ -95,7 +95,7 @@ fn main() { ..default() }, )]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::RED, diff --git a/examples/simple.rs b/examples/simple.rs index fbbd5ab..810460b 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -14,7 +14,7 @@ enum ScreenStates { fn main() { App::new() .add_plugins(DefaultPlugins) - .add_state::() + .init_state::() .add_plugins( SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu) .skipable() @@ -48,7 +48,7 @@ fn main() { }, ), ]) - .with_alignment(TextAlignment::Center), + .with_justify(JustifyText::Center), "FiraSans-Bold.ttf".to_string(), ), tint: Color::SEA_GREEN, diff --git a/src/lens.rs b/src/lens.rs index 32bde73..eaaea64 100644 --- a/src/lens.rs +++ b/src/lens.rs @@ -33,10 +33,9 @@ impl Lens for SplashTextColorLens { .iter_mut() .enumerate() .for_each(|(i, section)| { - let start: Vec4 = self.0[i].with_a(0.).into(); - let end: Vec4 = self.0[i].into(); - let value = start.lerp(end, ratio); - section.style.color = value.into(); + use crate::ColorLerper as _; + let value = self.0[i].with_a(0.).lerp(&self.0[i], ratio); + section.style.color = value; }); } } @@ -49,9 +48,8 @@ impl InstanceLens for SplashImageColorLens { impl Lens for SplashImageColorLens { 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; } } diff --git a/src/lib.rs b/src/lib.rs index ac89e90..ac30184 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,3 +132,21 @@ where ); } } + +/// 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) + } +} diff --git a/src/splash.rs b/src/splash.rs index 9a9a9a5..c85636f 100644 --- a/src/splash.rs +++ b/src/splash.rs @@ -98,7 +98,7 @@ pub(crate) fn create_splash( ..s.style }, })) - .with_alignment(text.alignment); + .with_justify(text.justify); cmd.spawn(( TextBundle { text: text.clone(),