|
|
|
@ -1,7 +1,4 @@
|
|
|
|
use bevy::{
|
|
|
|
use bevy::{prelude::*, utils::RandomState};
|
|
|
|
animation::{AnimationTarget, AnimationTargetId},
|
|
|
|
|
|
|
|
prelude::*,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{deck::Card, menu::UiMessage, setup::AnimationStore, GameState};
|
|
|
|
use crate::{deck::Card, menu::UiMessage, setup::AnimationStore, GameState};
|
|
|
|
|
|
|
|
|
|
|
|
@ -12,7 +9,8 @@ impl Plugin for PlayPlugin {
|
|
|
|
app.add_event::<ServeCards>()
|
|
|
|
app.add_event::<ServeCards>()
|
|
|
|
.add_observer(serve_cards)
|
|
|
|
.add_observer(serve_cards)
|
|
|
|
.add_systems(OnEnter(GameState::Main), deal_cards)
|
|
|
|
.add_systems(OnEnter(GameState::Main), deal_cards)
|
|
|
|
.add_systems(Update, deal_cards.run_if(set_added));
|
|
|
|
.add_systems(Update, deal_cards.run_if(set_added))
|
|
|
|
|
|
|
|
.add_systems(Update, delayed_animation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -40,35 +38,37 @@ pub(crate) fn toggle_selected(
|
|
|
|
trigger: Trigger<Pointer<Click>>,
|
|
|
|
trigger: Trigger<Pointer<Click>>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
selections: Query<&Selected>,
|
|
|
|
selections: Query<&Selected>,
|
|
|
|
mut query: Query<(&Name, &mut AnimationPlayer)>,
|
|
|
|
|
|
|
|
store: Res<AnimationStore>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
commands.trigger(UiMessage("".into()));
|
|
|
|
commands.trigger(UiMessage("".into()));
|
|
|
|
let e = trigger.entity();
|
|
|
|
let e = trigger.entity();
|
|
|
|
let (g, ai) = store.store.get("rotate".into()).unwrap();
|
|
|
|
|
|
|
|
let (n, mut ap) = query.get_mut(e).unwrap();
|
|
|
|
|
|
|
|
ap.stop_all();
|
|
|
|
|
|
|
|
if selections.contains(e) {
|
|
|
|
if selections.contains(e) {
|
|
|
|
commands.entity(e).remove::<Selected>();
|
|
|
|
commands.entity(e).remove::<Selected>();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ap.play(ai.clone()).repeat();
|
|
|
|
commands.entity(e).insert(Selected);
|
|
|
|
commands.entity(e).insert((
|
|
|
|
|
|
|
|
Selected,
|
|
|
|
|
|
|
|
g.clone(),
|
|
|
|
|
|
|
|
AnimationTarget {
|
|
|
|
|
|
|
|
id: AnimationTargetId::from_name(n),
|
|
|
|
|
|
|
|
player: e,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Observer system for resetting rotation when a card is de-selected
|
|
|
|
pub(crate) fn play_selected_animation(
|
|
|
|
pub(crate) fn reset_rotation(
|
|
|
|
trigger: Trigger<OnAdd, Selected>,
|
|
|
|
|
|
|
|
mut query: Query<&mut AnimationPlayer>,
|
|
|
|
|
|
|
|
store: Res<AnimationStore>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let e = trigger.entity();
|
|
|
|
|
|
|
|
info!("Play selected animation {:?}", e);
|
|
|
|
|
|
|
|
let (g, ai) = store.store.get("rotate".into()).unwrap();
|
|
|
|
|
|
|
|
commands.entity(e).insert(g.clone());
|
|
|
|
|
|
|
|
query.get_mut(e).unwrap().play(ai.clone()).repeat();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn stop_selected_animation(
|
|
|
|
trigger: Trigger<OnRemove, Selected>,
|
|
|
|
trigger: Trigger<OnRemove, Selected>,
|
|
|
|
mut transforms: Query<&mut Transform>,
|
|
|
|
mut query: Query<(&mut Transform, &mut AnimationPlayer)>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let mut t = transforms.get_mut(trigger.entity()).unwrap();
|
|
|
|
let e = trigger.entity();
|
|
|
|
|
|
|
|
info!("Stop selected animation {:?}", e);
|
|
|
|
|
|
|
|
let (mut t, mut ap) = query.get_mut(e).unwrap();
|
|
|
|
|
|
|
|
ap.stop_all();
|
|
|
|
t.rotation = Quat::default();
|
|
|
|
t.rotation = Quat::default();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -223,6 +223,12 @@ fn set_added(query: Query<Entity, Added<SetNumber>>) -> bool {
|
|
|
|
!query.is_empty()
|
|
|
|
!query.is_empty()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
|
|
|
struct DelayedAnimation {
|
|
|
|
|
|
|
|
graph: AnimationGraphHandle,
|
|
|
|
|
|
|
|
delay: Timer,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// When a card is added to the board, place it on the screen
|
|
|
|
/// When a card is added to the board, place it on the screen
|
|
|
|
pub(crate) fn place_card(
|
|
|
|
pub(crate) fn place_card(
|
|
|
|
trigger: Trigger<OnAdd, PlayLocation>,
|
|
|
|
trigger: Trigger<OnAdd, PlayLocation>,
|
|
|
|
@ -235,6 +241,7 @@ pub(crate) fn place_card(
|
|
|
|
)>,
|
|
|
|
)>,
|
|
|
|
animation_store: Res<AnimationStore>,
|
|
|
|
animation_store: Res<AnimationStore>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
random_state: Local<RandomState>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let (entity, play_location, mut visibility, name, mut player) =
|
|
|
|
let (entity, play_location, mut visibility, name, mut player) =
|
|
|
|
query.get_mut(trigger.entity()).unwrap();
|
|
|
|
query.get_mut(trigger.entity()).unwrap();
|
|
|
|
@ -246,18 +253,35 @@ pub(crate) fn place_card(
|
|
|
|
|
|
|
|
|
|
|
|
player.play(animation_index.clone());
|
|
|
|
player.play(animation_index.clone());
|
|
|
|
|
|
|
|
|
|
|
|
commands.entity(entity).insert((
|
|
|
|
let delay = ((random_state.hash_one(entity) % 9) as f32 / 10.0) + 0.1;
|
|
|
|
graph_handle.clone(),
|
|
|
|
info!("Delay: {:?}", delay);
|
|
|
|
AnimationTarget {
|
|
|
|
commands.entity(entity).insert((DelayedAnimation {
|
|
|
|
id: AnimationTargetId::from_name(name),
|
|
|
|
graph: graph_handle.clone(),
|
|
|
|
player: entity,
|
|
|
|
delay: Timer::from_seconds(delay, TimerMode::Once),
|
|
|
|
},
|
|
|
|
},));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set it to visible
|
|
|
|
// Set it to visible
|
|
|
|
*visibility = Visibility::Inherited;
|
|
|
|
*visibility = Visibility::Inherited;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn delayed_animation(
|
|
|
|
|
|
|
|
mut query: Query<(Entity, &mut DelayedAnimation)>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
query
|
|
|
|
|
|
|
|
.iter_mut()
|
|
|
|
|
|
|
|
.for_each(|(entity, mut delayed_animation)| {
|
|
|
|
|
|
|
|
delayed_animation.delay.tick(time.delta());
|
|
|
|
|
|
|
|
if delayed_animation.delay.just_finished() {
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
|
|
|
.entity(entity)
|
|
|
|
|
|
|
|
.insert(delayed_animation.graph.clone())
|
|
|
|
|
|
|
|
.remove::<DelayedAnimation>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn card_placement(PlayLocation { x, y }: &PlayLocation) -> Vec3 {
|
|
|
|
pub(crate) fn card_placement(PlayLocation { x, y }: &PlayLocation) -> Vec3 {
|
|
|
|
let card_size = [100.0, 160.0];
|
|
|
|
let card_size = [100.0, 160.0];
|
|
|
|
let offset = Vec2::new(card_size[0] * 4.0, card_size[1] * 4.0) / 2.5;
|
|
|
|
let offset = Vec2::new(card_size[0] * 4.0, card_size[1] * 4.0) / 2.5;
|
|
|
|
|