Right-click to de-select pieces

main
Elijah C. Voigt 1 year ago
parent 6f53ff2611
commit 16d42f77cf

@ -47,6 +47,31 @@ impl Plugin for Display3dPlugin {
.run_if(on_event::<AssetEvent<Tweaks>>()), .run_if(on_event::<AssetEvent<Tweaks>>()),
), ),
) )
// 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::<MouseMotion>())
.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::<game::Selected>()),
de_select.run_if(just_pressed(MouseButton::Right)),
put_down.run_if(any_component_removed::<game::Selected>()),
)
)
.add_systems( .add_systems(
Update, Update,
( (
@ -77,24 +102,6 @@ impl Plugin for Display3dPlugin {
set_title_model.run_if(any_component_added::<TitleText>()), set_title_model.run_if(any_component_added::<TitleText>()),
set_valid_move_model.run_if(any_component_added::<game::ValidMove>()), set_valid_move_model.run_if(any_component_added::<game::ValidMove>()),
set_tile_hitbox.run_if(any_component_added::<game::Tile>()), set_tile_hitbox.run_if(any_component_added::<game::Tile>()),
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::<MouseMotion>())
.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::<game::Selected>()),
put_down.run_if(any_component_removed::<game::Selected>()),
dissolve_animation.run_if(any_with_component::<Dissolving>), dissolve_animation.run_if(any_with_component::<Dissolving>),
capture_piece_start.run_if(any_component_added::<game::BeingCaptured>()), capture_piece_start.run_if(any_component_added::<game::BeingCaptured>()),
capture_piece_end.run_if(any_component_removed::<Dissolving>()), capture_piece_end.run_if(any_component_removed::<Dissolving>()),
@ -933,6 +940,15 @@ fn pick_up(
}); });
} }
fn de_select(
query: Query<Entity, With<Selected>>,
mut commands: Commands,
) {
query.iter().for_each(|e| {
commands.entity(e).remove::<Selected>();
})
}
fn put_down( fn put_down(
mut events: RemovedComponents<game::Selected>, mut events: RemovedComponents<game::Selected>,
mut query: Query<Entity, (With<game::Piece>, With<game::Selectable>, With<Display3d>)>, mut query: Query<Entity, (With<game::Piece>, With<game::Selectable>, With<Display3d>)>,

Loading…
Cancel
Save