diff --git a/src/display3d.rs b/src/display3d.rs index 9cde979..1e22229 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -47,6 +47,31 @@ impl Plugin for Display3dPlugin { .run_if(on_event::>()), ), ) + // Piece selection + .add_systems( + Update, + ( + entity_pointer + .run_if(in_state(GameState::Play)) + .run_if(in_state(DisplayState::Display3d)) + // Run if in debug state on mouse events + // Or just run when the left mouse button is clicked + .run_if( + in_state(debug::DebugState::Enabled) + .and_then(on_event::()) + .or_else(just_pressed(MouseButton::Left)), + ) + .before(select), + select + .run_if(in_state(GameState::Play)) + .run_if(in_state(DisplayState::Display3d)) + .run_if(not(in_state(MenuState::On))) + .run_if(just_pressed(MouseButton::Left)), + pick_up.run_if(any_component_added::()), + de_select.run_if(just_pressed(MouseButton::Right)), + put_down.run_if(any_component_removed::()), + ) + ) .add_systems( Update, ( @@ -77,24 +102,6 @@ impl Plugin for Display3dPlugin { set_title_model.run_if(any_component_added::()), set_valid_move_model.run_if(any_component_added::()), set_tile_hitbox.run_if(any_component_added::()), - entity_pointer - .run_if(in_state(GameState::Play)) - .run_if(in_state(DisplayState::Display3d)) - // Run if in debug state on mouse events - // Or just run when the left mouse button is clicked - .run_if( - in_state(debug::DebugState::Enabled) - .and_then(on_event::()) - .or_else(just_pressed(MouseButton::Left)), - ) - .before(select), - select - .run_if(in_state(GameState::Play)) - .run_if(in_state(DisplayState::Display3d)) - .run_if(not(in_state(MenuState::On))) - .run_if(just_pressed(MouseButton::Left)), - pick_up.run_if(any_component_added::()), - put_down.run_if(any_component_removed::()), dissolve_animation.run_if(any_with_component::), capture_piece_start.run_if(any_component_added::()), capture_piece_end.run_if(any_component_removed::()), @@ -933,6 +940,15 @@ fn pick_up( }); } +fn de_select( + query: Query>, + mut commands: Commands, +) { + query.iter().for_each(|e| { + commands.entity(e).remove::(); + }) +} + fn put_down( mut events: RemovedComponents, mut query: Query, With, With)>,