Skip to content
Snippets Groups Projects
components.rs 1.63 KiB
Newer Older
use micro_musicbox::prelude::AudioSource;
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
use std::time::Duration;
use bevy_asset::Handle;

use bevy_ecs::prelude::*;
use bevy_render::prelude::*;

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

#[derive(Clone, Copy, Debug)]
pub struct SplashStep {
	duration: f32,
	step_type: SplashStepType,
}

pub type SplashAnimation = Vec<SplashStep>;

#[derive(Resource)]
pub struct LogoHandle(pub Handle<Image>);
impl Deref for LogoHandle {
	type Target = Handle<Image>;
	fn deref(&self) -> &Self::Target {
		&self.0
	}
}
#[derive(Resource)]
pub struct StingHandle(pub Handle<AudioSource>);
impl Deref for StingHandle {
	type Target = Handle<AudioSource>;
	fn deref(&self) -> &Self::Target {
		&self.0
	}
}

#[derive(Clone, Debug, Resource, Default)]
pub struct SplashSettings<StateType: States> {
	pub run_in: StateType,
	pub transition_to: StateType,
	pub sting_path: String,
	pub logo_path: String,
	pub duration: Duration,
	pub skip_on_input: bool,
	pub bg_color_tween: Option<(Color, Color)>,
	pub logo_color_tween: Option<(Color, Color)>,
	pub tween_duration: Option<Duration>,
}

#[derive(Clone, Copy, Debug, Component)]
pub struct ScaleToWindow;

#[derive(Default, Resource)]
pub struct TweenClearColor {
	pub from: Color,
	pub to: Color,
	pub progress: Duration,
	pub duration: Duration,
}

#[derive(Default, Resource)]
pub struct SplashTime(pub Duration);
impl Deref for SplashTime {
	type Target = Duration;
	fn deref(&self) -> &Self::Target {
		&self.0
	}
}
impl DerefMut for SplashTime {
	fn deref_mut(&mut self) -> &mut Self::Target {
		&mut self.0
	}
}