From a47cd06a9347b61942166aac571d8e2836314990 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 31 Dec 2024 22:43:16 -0800 Subject: [PATCH] Fun SET! button --- src/animation.rs | 49 ++++++++++++++++++++++++++++++++----------- src/main.rs | 1 + src/menu.rs | 4 ++++ src/play.rs | 30 ++++++++++++++++++++++---- src/run_conditions.rs | 5 +++++ src/setup.rs | 2 +- todo.txt | 5 ----- 7 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 src/run_conditions.rs diff --git a/src/animation.rs b/src/animation.rs index 471aedb..7aaf535 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -2,6 +2,7 @@ use std::{f32::consts::PI, ops::RangeInclusive}; use bevy::{ animation::{animated_field, AnimationTarget, AnimationTargetId}, + color::palettes::css::{BLACK, BLUE, GREEN, PINK, RED}, prelude::*, utils::HashMap, }; @@ -15,7 +16,10 @@ pub struct AnimationPlugin; impl Plugin for AnimationPlugin { fn build(&self, app: &mut App) { - app.add_systems(Update, delayed_animation); + app.add_systems(Update, delayed_animation).add_systems( + Update, + animate_button.run_if(any_with_component::), + ); } } @@ -25,12 +29,11 @@ struct AnimationComplete; #[derive(Resource, Default)] pub(crate) struct AnimationStore { pub store: HashMap, - pub graph: AnimationGraphHandle, + pub card_graph: AnimationGraphHandle, } #[derive(Component)] pub(crate) struct DelayedAnimation { - pub graph: AnimationGraphHandle, pub animation_index: AnimationNodeIndex, pub delay: Timer, } @@ -126,13 +129,9 @@ pub(crate) fn setup_animations( }); } - animation_store.graph = AnimationGraphHandle(graphs.add(animation_graph)); + animation_store.card_graph = AnimationGraphHandle(graphs.add(animation_graph)); commands.insert_resource(animation_store); - - // TODO: (example: https://bevyengine.org/examples/animation/animated-transform/) - // Button Animations: - // active_button_animation = AnimationClip::default() // color and size } pub(crate) fn play_selected_animation( @@ -168,10 +167,36 @@ fn delayed_animation( delayed_animation.delay.tick(time.delta()); if delayed_animation.delay.just_finished() { animation_player.start(delayed_animation.animation_index); - commands - .entity(entity) - .insert(delayed_animation.graph.clone()) - .remove::(); + commands.entity(entity).remove::(); } }); } + +#[derive(Component)] +pub(crate) struct AnimateButton; + +pub(crate) fn animate_button( + query: Single<(&mut BackgroundColor, &mut Transform), With>, + time: Res