diff --git a/src/setup.rs b/src/setup.rs index c1afcfe..14f49c2 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -1,4 +1,4 @@ -use std::f32::consts::PI; +use std::{f32::consts::PI, ops::RangeInclusive}; use crate::{deck::*, *}; use bevy::{ @@ -120,30 +120,57 @@ fn setup_animations( } { - // Pre-req: requires deck location and helper function for each spot's placement // For each spot on board - // Move from deck location (TBD) to spot - // For each card - // Assign this curve to the target - // todo!("Setup deal animations"); - } - - { - // Pre-req: requires discard location and helper function for each spot's placement - // For each spot on board - // Move from spot location to discard pile (location TBD) - // For each card - // Assign this curve to the target - // todo!("Setup discard animations"); + RangeInclusive::::new(0, 3).for_each(|x| { + RangeInclusive::::new(0, 3).for_each(|y| { + let a = Vec3::new(-100.0, 0.0, 0.0); + let b = play::card_placement(&play::PlayLocation { x, y }); + let c = Vec3::new(100.0, 0.0, 0.0); + + // Serve Deck -> Spot Animation + { + let mut animation = AnimationClip::default(); + targets.iter().for_each(|target| { + let curve = AnimatableCurve::new( + animated_field!(Transform::translation), + AnimatableKeyframeCurve::new([0.0, 1.0].into_iter().zip([a, b])) + .expect("Serve Card animation"), + ); + animation.add_curve_to_target(*target, curve); + }); + let animation_handle = clips.add(animation); + let (graph, animation_index) = AnimationGraph::from_clip(animation_handle); + let graph_handle = AnimationGraphHandle(graphs.add(graph)); + animation_store.store.insert( + format!("deck->{:?}", (x, y)), + (graph_handle, animation_index), + ); + } + + // Spot -> Discard Animation + { + let mut animation = AnimationClip::default(); + targets.iter().for_each(|target| { + let curve = AnimatableCurve::new( + animated_field!(Transform::translation), + AnimatableKeyframeCurve::new([0.0, 1.0].into_iter().zip([b, c])) + .expect("Serve Card animation"), + ); + animation.add_curve_to_target(*target, curve); + }); + let animation_handle = clips.add(animation); + let (graph, animation_index) = AnimationGraph::from_clip(animation_handle); + let graph_handle = AnimationGraphHandle(graphs.add(graph)); + animation_store.store.insert( + format!("{:?}->discard", (x, y)), + (graph_handle, animation_index), + ); + } + }); + }); } commands.insert_resource(animation_store); - // Card Animations: - // active_card_animation = AnimationClip::default() // simple rotation - // for each (X, Y) in board: - // deck_to_X_Y = AnimationClip::default() // Move from deck to X Y position - // X_Y_to_sets = AnimationClip::default() // Move from X Y position to sets pile - // All need AnimationTarget, AnimationGraphHandle, and AnimationPlayer // TODO: (example: https://bevyengine.org/examples/animation/animated-transform/) // Button Animations: // active_button_animation = AnimationClip::default() // color and size diff --git a/todo.txt b/todo.txt index 84c1113..4576929 100644 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,9 @@ TODO: -* Better shuffling +* BUG: Help does not animate rotating cards * Make "set" button visually interesting when 3 cards selected * Animate cards deck -> board * Animate cards deck -> set-pile +* Better shuffling Later: * View all cards with some indication of in-set