From 97640c383c15d4cfa473e9842ad421d4e5092817 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 30 Mar 2024 21:14:04 +0100 Subject: [PATCH] add a cozy fade-in from black on start --- src/effects.rs | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 ++ src/settings.rs | 8 +++++ 3 files changed, 102 insertions(+) create mode 100644 src/effects.rs diff --git a/src/effects.rs b/src/effects.rs new file mode 100644 index 0000000..c7e3174 --- /dev/null +++ b/src/effects.rs @@ -0,0 +1,92 @@ +use bevy::prelude::*; +use crate::settings; + +pub struct EffectsPlugin; + +impl Plugin for EffectsPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, setup); + app.add_systems(Startup, spawn_effects.after(setup)); + app.add_systems(Update, spawn_effects); + app.add_systems(Update, update_fadeblack); + app.add_event::(); + } +} + +#[derive(Clone)] +pub enum Effects { + FadeIn, +} + +#[derive(Component)] pub struct FadeBlack; +#[derive(Component)] +pub struct Effect { + pub class: Effects, + pub duration: f64, + pub start_time: f64, +} +#[derive(Event)] +pub struct SpawnEffectEvent { + pub class: Effects, + pub duration: f64, +} + +pub fn setup( + settings: Res, + mut ew_effect: EventWriter, +) { + if !settings.dev_mode { + ew_effect.send(SpawnEffectEvent { class: Effects::FadeIn, duration: 4.0 }); + } +} + +pub fn spawn_effects( + mut commands: Commands, + mut er_effect: EventReader, + time: Res