diff --git a/src/display3d.rs b/src/display3d.rs index 56d7a6f..4addff8 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -2,10 +2,7 @@ // Intro animation // Turn changing animations // TODO: Pickup/put-down sound in 3d -// TODO: Unify the selection logic -// If you select in 2d, it should "be" selected in 3d. -// And if you select in 3d, 2d is selected. -// TODO: De-select pieces +// TODO: Background during menu use crate::{ game::{Board, BoardIndex, Piece, Side}, @@ -564,7 +561,7 @@ fn pick_up( animation.expect("Pickup Animation").clone(), Duration::from_secs_f32(0.75), ) - .play_with_transition( + .start_with_transition( idle.expect("Idle animation").clone(), Duration::from_secs_f32(1.5), ) @@ -593,7 +590,7 @@ fn put_down( game::Piece::Pawn => gltf.named_animations.get("PawnPutDown"), }; player - .play_with_transition( + .start_with_transition( animation.expect("PutDown Animation").clone(), Duration::from_secs_f32(0.75), ) diff --git a/src/game.rs b/src/game.rs index 57eb053..9038d6b 100644 --- a/src/game.rs +++ b/src/game.rs @@ -19,6 +19,10 @@ impl Plugin for GamePlugin { select_sync.run_if(any_component_added::), deselect_sync.run_if(any_component_removed::()), move_piece.run_if(any_component_added::), + exclusive_select:: + .run_if(any_component_added::), + exclusive_select:: + .run_if(any_component_added::), ), ) .add_systems( @@ -334,6 +338,7 @@ fn deselect_sync( }) } +/// Triggered when right-mouse-button clicked fn cancel_place(current: Query, With)>, mut commands: Commands) { current.iter().for_each(|entity| { info!("De-selecting {:?}", entity); @@ -368,3 +373,19 @@ fn move_piece( commands.entity(tile).remove::(); }); } + +/// TEMPORARY: Exclusive selection; only select one piece at a time +fn exclusive_select( + events: Query, With, With)>, + selected: Query, With, With)>, + 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::(); + }); + }); +}