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 #18

Merged
merged 3 commits into from
Mar 18, 2024
Merged
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 @@ -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",
Expand Down Expand Up @@ -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" }
8 changes: 4 additions & 4 deletions examples/custom_skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum ScreenStates {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_state::<ScreenStates>()
.init_state::<ScreenStates>()
.add_plugins(
SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu)
.ignore_default_events()
Expand All @@ -41,7 +41,7 @@ fn main() {
},
),
])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
Expand All @@ -64,7 +64,7 @@ fn main() {
..default()
},
)
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
Expand Down Expand Up @@ -124,7 +124,7 @@ fn create_scene(mut cmd: Commands, assets: ResMut<AssetServer>) {
..default()
},
)
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
..default()
},
Animator::new(
Expand Down
14 changes: 7 additions & 7 deletions examples/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum ScreenStates {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_state::<ScreenStates>()
.init_state::<ScreenStates>()
.add_plugins(
SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu)
.skipable()
Expand Down Expand Up @@ -48,7 +48,7 @@ fn main() {
},
),
])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::SEA_GREEN,
Expand All @@ -68,7 +68,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
Expand All @@ -95,7 +95,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::YELLOW,
Expand All @@ -115,7 +115,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::BLUE,
Expand All @@ -135,7 +135,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
Expand All @@ -155,7 +155,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::PURPLE,
Expand Down
8 changes: 4 additions & 4 deletions examples/screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum ScreenStates {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_state::<ScreenStates>()
.init_state::<ScreenStates>()
.add_plugins(
SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu)
.add_screen(SplashScreen {
Expand Down Expand Up @@ -46,7 +46,7 @@ fn main() {
},
),
])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::SEA_GREEN,
Expand All @@ -70,7 +70,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
Expand All @@ -95,7 +95,7 @@ fn main() {
..default()
},
)])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::RED,
Expand Down
4 changes: 2 additions & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum ScreenStates {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_state::<ScreenStates>()
.init_state::<ScreenStates>()
.add_plugins(
SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu)
.skipable()
Expand Down Expand Up @@ -48,7 +48,7 @@ fn main() {
},
),
])
.with_alignment(TextAlignment::Center),
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::SEA_GREEN,
Expand Down
14 changes: 6 additions & 8 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ impl Lens<Text> 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;
});
}
}
Expand All @@ -49,9 +48,8 @@ impl InstanceLens for SplashImageColorLens {

impl Lens<BackgroundColor> 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;
}
}
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/splash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading