|
|
|
|
@ -2,8 +2,9 @@ use std::f32::consts::PI;
|
|
|
|
|
|
|
|
|
|
use crate::{deck::*, *};
|
|
|
|
|
use bevy::{
|
|
|
|
|
animation::{animated_field, AnimationTarget, AnimationTargetId},
|
|
|
|
|
animation::{animated_field, AnimationTargetId},
|
|
|
|
|
prelude::*,
|
|
|
|
|
utils::HashMap,
|
|
|
|
|
};
|
|
|
|
|
use view::ViewState;
|
|
|
|
|
|
|
|
|
|
@ -13,23 +14,25 @@ impl Plugin for SetupPlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_systems(
|
|
|
|
|
OnEnter(GameState::Setup),
|
|
|
|
|
(setup_background, setup_cards, setup_camera, start_play).chain(),
|
|
|
|
|
(
|
|
|
|
|
setup_background,
|
|
|
|
|
setup_cards,
|
|
|
|
|
setup_camera,
|
|
|
|
|
start_play,
|
|
|
|
|
setup_animations,
|
|
|
|
|
)
|
|
|
|
|
.chain(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
pub(crate) struct CardAnimations {
|
|
|
|
|
pub rotate: AnimationNodeIndex,
|
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
|
pub(crate) struct AnimationStore {
|
|
|
|
|
pub store: HashMap<String, (AnimationGraphHandle, AnimationNodeIndex)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Setup drawing our cards on the screen
|
|
|
|
|
pub(crate) fn setup_cards(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
deck: Res<Deck>,
|
|
|
|
|
mut clips: ResMut<Assets<AnimationClip>>,
|
|
|
|
|
mut graphs: ResMut<Assets<AnimationGraph>>,
|
|
|
|
|
) {
|
|
|
|
|
pub(crate) fn setup_cards(mut commands: Commands, deck: Res<Deck>) {
|
|
|
|
|
let animation_player = AnimationPlayer::default();
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
@ -53,56 +56,79 @@ pub(crate) fn setup_cards(
|
|
|
|
|
};
|
|
|
|
|
let order = play::DeckOrder(i as u8);
|
|
|
|
|
|
|
|
|
|
let animation_player = AnimationPlayer::default();
|
|
|
|
|
|
|
|
|
|
let name = Name::new(format!("{}", this_card));
|
|
|
|
|
let animation_components = {
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
this_sprite,
|
|
|
|
|
this_card,
|
|
|
|
|
order,
|
|
|
|
|
Visibility::Hidden,
|
|
|
|
|
name,
|
|
|
|
|
animation_player,
|
|
|
|
|
))
|
|
|
|
|
.observe(play::place_card)
|
|
|
|
|
.observe(debug::set_debug_card)
|
|
|
|
|
.observe(debug::hide_debug_card)
|
|
|
|
|
.observe(play::reset_rotation)
|
|
|
|
|
.observe(play::toggle_selected);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn setup_animations(
|
|
|
|
|
mut clips: ResMut<Assets<AnimationClip>>,
|
|
|
|
|
mut graphs: ResMut<Assets<AnimationGraph>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
let mut animation_store = AnimationStore::default();
|
|
|
|
|
|
|
|
|
|
let targets: Vec<AnimationTargetId> = Deck::iter_cards()
|
|
|
|
|
.map(|c| Name::new(format!("{}", c)))
|
|
|
|
|
.map(|n| AnimationTargetId::from_name(&n))
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
// Rotation Animation
|
|
|
|
|
{
|
|
|
|
|
let mut animation = AnimationClip::default();
|
|
|
|
|
let target = AnimationTargetId::from_name(&name);
|
|
|
|
|
targets.iter().for_each(|target| {
|
|
|
|
|
let curve = AnimatableCurve::new(
|
|
|
|
|
animated_field!(Transform::rotation),
|
|
|
|
|
AnimatableKeyframeCurve::new(
|
|
|
|
|
[0.0, 1.0, 2.0, 3.0, 4.0].into_iter().zip([
|
|
|
|
|
[0.0, 1.0, 2.0, 3.0, 4.0]
|
|
|
|
|
.map(|i| i * 5.0) // TODO: Make this tuneable
|
|
|
|
|
.into_iter()
|
|
|
|
|
.zip([
|
|
|
|
|
Quat::IDENTITY,
|
|
|
|
|
Quat::from_axis_angle(Vec3::Y, PI / 2.),
|
|
|
|
|
Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
|
|
|
|
|
Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
|
|
|
|
|
Quat::from_axis_angle(Vec3::Z, PI / 2.),
|
|
|
|
|
Quat::from_axis_angle(Vec3::Z, PI / 2. * 2.),
|
|
|
|
|
Quat::from_axis_angle(Vec3::Z, PI / 2. * 3.),
|
|
|
|
|
Quat::IDENTITY,
|
|
|
|
|
]),
|
|
|
|
|
)
|
|
|
|
|
.expect("Rotation animation"),
|
|
|
|
|
);
|
|
|
|
|
animation.add_curve_to_target(target, curve);
|
|
|
|
|
animation.add_curve_to_target(*target, curve);
|
|
|
|
|
});
|
|
|
|
|
let animation_handle = clips.add(animation);
|
|
|
|
|
let (graph, rotate) = AnimationGraph::from_clip(animation_handle);
|
|
|
|
|
let animation_graph_handle = AnimationGraphHandle(graphs.add(graph));
|
|
|
|
|
let indexes = CardAnimations { rotate };
|
|
|
|
|
let target = AnimationTarget {
|
|
|
|
|
id: target,
|
|
|
|
|
player: parent.parent_entity(),
|
|
|
|
|
};
|
|
|
|
|
(animation_graph_handle, indexes, target)
|
|
|
|
|
};
|
|
|
|
|
let (graph, animation_index) = AnimationGraph::from_clip(animation_handle);
|
|
|
|
|
let graph_handle = AnimationGraphHandle(graphs.add(graph));
|
|
|
|
|
animation_store
|
|
|
|
|
.store
|
|
|
|
|
.insert("rotate".into(), (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
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
this_sprite,
|
|
|
|
|
this_card,
|
|
|
|
|
order,
|
|
|
|
|
Visibility::Hidden,
|
|
|
|
|
name,
|
|
|
|
|
animation_components,
|
|
|
|
|
))
|
|
|
|
|
.observe(play::place_card)
|
|
|
|
|
.observe(debug::set_debug_card)
|
|
|
|
|
.observe(debug::hide_debug_card)
|
|
|
|
|
.observe(play::reset_rotation)
|
|
|
|
|
.observe(play::toggle_selected);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
// TODO: (example: https://bevyengine.org/examples/animation/animated-transform/)
|
|
|
|
|
// Button Animations:
|
|
|
|
|
// active_button_animation = AnimationClip::default() // color and size
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Setup our camera to view cardson the screen
|
|
|
|
|
@ -140,9 +166,3 @@ pub(crate) fn start_play(
|
|
|
|
|
game_state.set(GameState::Main);
|
|
|
|
|
view_state.set(ViewState::Menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn setup_animations(mut commands: Commands) {
|
|
|
|
|
// TODO: (example: https://bevyengine.org/examples/animation/animated-transform/)
|
|
|
|
|
// Button Animations:
|
|
|
|
|
// active_button_animation = AnimationClip::default() // color and size
|
|
|
|
|
}
|
|
|
|
|
|