exclusive selection

bevy0.12
Elijah C. Voigt 2 years ago
parent ade967fb67
commit a5bb2aa385

@ -2,10 +2,7 @@
// Intro animation // Intro animation
// Turn changing animations // Turn changing animations
// TODO: Pickup/put-down sound in 3d // TODO: Pickup/put-down sound in 3d
// TODO: Unify the selection logic // TODO: Background during menu
// If you select in 2d, it should "be" selected in 3d.
// And if you select in 3d, 2d is selected.
// TODO: De-select pieces
use crate::{ use crate::{
game::{Board, BoardIndex, Piece, Side}, game::{Board, BoardIndex, Piece, Side},
@ -564,7 +561,7 @@ fn pick_up(
animation.expect("Pickup Animation").clone(), animation.expect("Pickup Animation").clone(),
Duration::from_secs_f32(0.75), Duration::from_secs_f32(0.75),
) )
.play_with_transition( .start_with_transition(
idle.expect("Idle animation").clone(), idle.expect("Idle animation").clone(),
Duration::from_secs_f32(1.5), Duration::from_secs_f32(1.5),
) )
@ -593,7 +590,7 @@ fn put_down(
game::Piece::Pawn => gltf.named_animations.get("PawnPutDown"), game::Piece::Pawn => gltf.named_animations.get("PawnPutDown"),
}; };
player player
.play_with_transition( .start_with_transition(
animation.expect("PutDown Animation").clone(), animation.expect("PutDown Animation").clone(),
Duration::from_secs_f32(0.75), Duration::from_secs_f32(0.75),
) )

@ -19,6 +19,10 @@ impl Plugin for GamePlugin {
select_sync.run_if(any_component_added::<Selected>), select_sync.run_if(any_component_added::<Selected>),
deselect_sync.run_if(any_component_removed::<Selected>()), deselect_sync.run_if(any_component_removed::<Selected>()),
move_piece.run_if(any_component_added::<Selected>), move_piece.run_if(any_component_added::<Selected>),
exclusive_select::<display2d::Display2d>
.run_if(any_component_added::<Selected>),
exclusive_select::<display2d::Display2d>
.run_if(any_component_added::<Selected>),
), ),
) )
.add_systems( .add_systems(
@ -334,6 +338,7 @@ fn deselect_sync(
}) })
} }
/// Triggered when right-mouse-button clicked
fn cancel_place(current: Query<Entity, (With<Selected>, With<Piece>)>, mut commands: Commands) { fn cancel_place(current: Query<Entity, (With<Selected>, With<Piece>)>, mut commands: Commands) {
current.iter().for_each(|entity| { current.iter().for_each(|entity| {
info!("De-selecting {:?}", entity); info!("De-selecting {:?}", entity);
@ -368,3 +373,19 @@ fn move_piece(
commands.entity(tile).remove::<Selected>(); commands.entity(tile).remove::<Selected>();
}); });
} }
/// TEMPORARY: Exclusive selection; only select one piece at a time
fn exclusive_select<T: Component>(
events: Query<Entity, (Added<Selected>, With<Piece>, With<T>)>,
selected: Query<Entity, (With<Selected>, With<Piece>, With<T>)>,
mut commands: Commands,
) {
// Iterate over selected component markers on pieces
events.iter().for_each(|entity| {
// Selected > 2 (one for each display2d/3d)
selected.iter().filter(|&e| e != entity).for_each(|e| {
// Remove the previously added selected marker
commands.entity(e).remove::<Selected>();
});
});
}

Loading…
Cancel
Save