Skip to content
Snippets Groups Projects
components.rs 1.02 KiB
Newer Older
Louis's avatar
Louis committed
use bevy::prelude::*;

#[derive(Clone)]
pub enum SplashAnimationType {
	FadeColour { from: Color, to: Color },
	Wait,
}

#[derive(Component, Clone)]
pub struct SplashAnimation {
	pub duration: f32,
	pub anim: SplashAnimationType,
	pub then: Option<Box<SplashAnimation>>,
}

#[derive(Component, Clone)]
pub struct SplashAnimationTimer(pub f32);

#[derive(Bundle)]
pub struct SplashAnimationBundle {
	animation: SplashAnimation,
	timer: SplashAnimationTimer,
}

impl SplashAnimationBundle {
	pub fn from_animation(animation: SplashAnimation) -> Self {
		Self {
			animation,
			timer: SplashAnimationTimer(0.0),
		}
	}
}

impl SplashAnimation {
	pub fn fade(
		from: Color,
		to: Color,
		duration: f32,
		then: Option<Box<SplashAnimation>>,
	) -> SplashAnimation {
		SplashAnimation {
			anim: SplashAnimationType::FadeColour { from, to },
			duration,
			then,
		}
	}

	pub fn wait(duration: f32, then: Option<Box<SplashAnimation>>) -> SplashAnimation {
		SplashAnimation {
			anim: SplashAnimationType::Wait,
			duration,
			then,
		}
	}
}