Skip to content

Commit

Permalink
Upgraded to bevy 0.14 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezan7CC authored Aug 11, 2024
1 parent df28b30 commit d523d3b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 53 deletions.
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ opt-level = 1
opt-level = 3

[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = [
"multi-threaded",
bevy = { version = "0.14.1", default-features = false, features = [
"multi_threaded",
"bevy_asset",
"bevy_winit",
"bevy_render",
"bevy_sprite",
"bevy_state",
"png",
] }

Expand All @@ -35,9 +36,10 @@ dev = [
"bevy/bevy_core_pipeline",
"bevy/bevy_render",
"bevy/bevy_sprite",
"bevy/bevy_state",
"bevy/bevy_text",
"bevy/bevy_ui",
"bevy/multi-threaded",
"bevy/multi_threaded",
"bevy/png",
"bevy/ktx2",
"bevy/x11",
Expand Down Expand Up @@ -66,8 +68,10 @@ required-features = ["dev"]
path = "./examples/simple.rs"

[dependencies]
bevy = { version = "0.13", default-features = false }
bevy_tweening = "0.10"
bevy = { version = "0.14.1", default-features = false , features = [
"bevy_state",
] }
bevy_tweening = "0.11.0"

[patch.crates-io]
bevy_tweening = { git = "https://github.com/SergioRibera/bevy_tweening", branch = "infinite_mirrored" }
9 changes: 4 additions & 5 deletions examples/custom_skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() {
)
.add_systems(Startup, create_scene)
.add_systems(Update, button_system)
.run()
.run();
}

fn create_scene(mut cmd: Commands, assets: ResMut<AssetServer>) {
Expand Down Expand Up @@ -110,7 +110,7 @@ fn create_scene(mut cmd: Commands, assets: ResMut<AssetServer>) {
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor(Color::WHITE.with_a(0.)),
background_color: BackgroundColor(Color::WHITE.with_alpha(0.)),
..default()
})
.with_children(|cmd| {
Expand Down Expand Up @@ -146,9 +146,8 @@ fn button_system(
mut send_skip: EventWriter<SplashScreenSkipEvent>,
) {
for interaction in &mut interaction_query {
match *interaction {
Interaction::Pressed => send_skip.send(SplashScreenSkipEvent),
_ => {}
if *interaction == Interaction::Pressed {
send_skip.send(SplashScreenSkipEvent);
}
}
}
16 changes: 8 additions & 8 deletions examples/layouts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::time::Duration;

use bevy::color::palettes;
use bevy::prelude::*;
use bevy_splash_screen::{SplashAssetType, SplashItem, SplashPlugin, SplashScreen, SplashType};
use bevy_tweening::EaseFunction;
use std::time::Duration;

#[derive(Clone, Copy, Debug, Default, States, Hash, PartialEq, Eq)]
enum ScreenStates {
Expand Down Expand Up @@ -35,7 +35,7 @@ fn main() {
"by\n",
TextStyle {
font_size: 24.,
color: Color::WHITE.with_a(0.75),
color: Color::WHITE.with_alpha(0.75),
..default()
},
),
Expand All @@ -51,7 +51,7 @@ fn main() {
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::SEA_GREEN,
tint: palettes::css::SEA_GREEN.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand Down Expand Up @@ -98,7 +98,7 @@ fn main() {
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::YELLOW,
tint: palettes::basic::YELLOW.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand All @@ -118,7 +118,7 @@ fn main() {
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::BLUE,
tint: Srgba::BLUE.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand Down Expand Up @@ -158,7 +158,7 @@ fn main() {
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::PURPLE,
tint: palettes::basic::PURPLE.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand All @@ -173,7 +173,7 @@ fn main() {
}),
)
.add_systems(Startup, create_scene)
.run()
.run();
}

fn create_scene(mut cmd: Commands) {
Expand Down
12 changes: 6 additions & 6 deletions examples/screens.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::time::Duration;

use bevy::color::palettes;
use bevy::prelude::*;
use bevy_splash_screen::{SplashAssetType, SplashItem, SplashPlugin, SplashScreen};
use bevy_tweening::EaseFunction;
use std::time::Duration;

#[derive(Clone, Copy, Debug, Default, States, Hash, PartialEq, Eq)]
enum ScreenStates {
Expand Down Expand Up @@ -33,7 +33,7 @@ fn main() {
"by\n",
TextStyle {
font_size: 24.,
color: Color::WHITE.with_a(0.75),
color: Color::WHITE.with_alpha(0.75),
..default()
},
),
Expand All @@ -49,7 +49,7 @@ fn main() {
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::SEA_GREEN,
tint: palettes::css::SEA_GREEN.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand Down Expand Up @@ -98,7 +98,7 @@ fn main() {
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::RED,
tint: Srgba::RED.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand All @@ -111,7 +111,7 @@ fn main() {
}),
)
.add_systems(Startup, create_scene)
.run()
.run();
}

fn create_scene(mut cmd: Commands) {
Expand Down
12 changes: 6 additions & 6 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::time::Duration;

use bevy::color::palettes;
use bevy::prelude::*;
use bevy_splash_screen::{SplashAssetType, SplashItem, SplashPlugin, SplashScreen};
use bevy_tweening::EaseFunction;
use std::time::Duration;

#[derive(Clone, Copy, Debug, Default, States, Hash, PartialEq, Eq)]
enum ScreenStates {
Expand Down Expand Up @@ -35,23 +35,23 @@ fn main() {
"by\n",
TextStyle {
font_size: 24.,
color: Color::WHITE.with_a(0.75),
color: Color::WHITE.with_alpha(0.75),
..default()
},
),
TextSection::new(
"Sergio Ribera",
TextStyle {
font_size: 32.,
color: Color::BLUE,
color: Srgba::BLUE.into(),
..default()
},
),
])
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::SEA_GREEN,
tint: palettes::css::SEA_GREEN.into(),
width: Val::Percent(30.),
height: Val::Px(150.),
ease_function: EaseFunction::QuarticInOut.into(),
Expand All @@ -73,7 +73,7 @@ fn main() {
}),
)
.add_systems(Startup, create_scene)
.run()
.run();
}

fn create_scene(mut cmd: Commands) {
Expand Down
11 changes: 6 additions & 5 deletions src/lens.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::prelude::*;
use bevy_tweening::lens::*;
use bevy_tweening::Targetable;

pub trait InstanceLens {
fn create(start: Color, end: Color) -> Self;
Expand Down Expand Up @@ -27,14 +28,14 @@ impl SplashTextColorLens {
}

impl Lens<Text> for SplashTextColorLens {
fn lerp(&mut self, target: &mut Text, ratio: f32) {
fn lerp(&mut self, target: &mut dyn Targetable<Text>, ratio: f32) {
target
.sections
.iter_mut()
.enumerate()
.for_each(|(i, section)| {
use crate::ColorLerper as _;
let value = self.0[i].with_a(0.).lerp(&self.0[i], ratio);
let value = self.0[i].with_alpha(0.).lerp(&self.0[i], ratio);
section.style.color = value;
});
}
Expand All @@ -46,10 +47,10 @@ impl InstanceLens for SplashImageColorLens {
}
}

impl Lens<BackgroundColor> for SplashImageColorLens {
fn lerp(&mut self, target: &mut BackgroundColor, ratio: f32) {
impl Lens<UiImage> for SplashImageColorLens {
fn lerp(&mut self, target: &mut dyn Targetable<UiImage>, ratio: f32) {
use crate::ColorLerper as _;
let value = self.start.lerp(&self.end, ratio);
target.0 = value;
target.color = value;
}
}
22 changes: 12 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use bevy::prelude::*;
use bevy::state::state::FreelyMutableState;
use bevy_tweening::*;

mod lens;
Expand Down Expand Up @@ -61,7 +62,7 @@ pub(crate) struct SplashScreenSkipable(bool, bool);
#[derive(Default, Clone, Resource)]
pub(crate) struct SplashScreens(Vec<SplashScreen>);

pub struct SplashPlugin<S> {
pub struct SplashPlugin<S: FreelyMutableState> {
state: S,
next: S,
skipable: bool,
Expand All @@ -71,7 +72,7 @@ pub struct SplashPlugin<S> {

impl<S> SplashPlugin<S>
where
S: States,
S: FreelyMutableState,
{
pub fn new(splash_state: S, next_state: S) -> Self {
Self {
Expand Down Expand Up @@ -101,7 +102,7 @@ where

impl<S> Plugin for SplashPlugin<S>
where
S: States,
S: FreelyMutableState,
{
fn build(&self, app: &mut App) {
if self.screens.0.is_empty() {
Expand All @@ -124,8 +125,7 @@ where
.add_systems(
Update,
(
component_animator_system::<BackgroundColor>
.run_if(in_state(self.state.clone())),
component_animator_system::<UiImage>.run_if(in_state(self.state.clone())),
update_splash::<S>.run_if(in_state(self.state.clone())),
splash_skip::<S>,
),
Expand All @@ -143,10 +143,12 @@ trait ColorLerper {
#[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)
let mut linear = self.to_linear();
let linear_target = target.to_linear();
linear.red = linear.red.lerp(linear_target.red, ratio);
linear.green = linear.green.lerp(linear_target.green, ratio);
linear.blue = linear.blue.lerp(linear_target.blue, ratio);
linear.alpha = linear.alpha.lerp(linear_target.alpha, ratio);
linear.into()
}
}
9 changes: 5 additions & 4 deletions src/splash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) fn create_splash(
SplashTextColorLens::new(
text.sections
.iter()
.map(|_| Color::WHITE.with_a(0.))
.map(|_| Color::WHITE.with_alpha(0.))
.collect(),
),
)
Expand Down Expand Up @@ -148,6 +148,7 @@ pub(crate) fn create_splash(
texture: assets.load(handler),
flip_x: false,
flip_y: false,
..default()
},
style: Style {
width: brand.width,
Expand All @@ -156,7 +157,7 @@ pub(crate) fn create_splash(
},
..default()
},
create_animator::<BackgroundColor, SplashImageColorLens>(
create_animator::<UiImage, SplashImageColorLens>(
brand,
max_duration,
i_screen,
Expand All @@ -181,14 +182,14 @@ where
Tween::new(
brand.ease_function,
Duration::from_secs(1),
L::create(brand.tint.with_a(0.), brand.tint.with_a(0.)),
L::create(brand.tint.with_alpha(0.), brand.tint.with_alpha(0.)),
)
.then(
Delay::new(max_duration).then(
Tween::new(
brand.ease_function,
brand.duration,
L::create(brand.tint.with_a(0.), brand.tint),
L::create(brand.tint.with_alpha(0.), brand.tint),
)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat)
.with_repeat_count(RepeatCount::Finite(2))
Expand Down
Loading

0 comments on commit d523d3b

Please sign in to comment.