Skip to content

Commit

Permalink
Address feadback
Browse files Browse the repository at this point in the history
  • Loading branch information
NthTensor committed Sep 4, 2024
1 parent 9b23706 commit a3edeaf
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 63 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_picking/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
//!
//! The order in which interaction events are received is extremely important, and you can read more
//! about it on the docs for the dispatcher system: [`pointer_events`]. This system runs in
//! [`PreUpdate`](bevy_app::PreUpdate) in [`Focus`](crate::PickSet::Focus). All pointer-event observers
//! resolve during the sync point between [`pointer_events`] and
//! [`PreUpdate`](bevy_app::PreUpdate) in [`PickSet::Focus`](crate::PickSet::Focus). All pointer-event
//! observers resolve during the sync point between [`pointer_events`] and
//! [`update_interactions`](crate::focus::update_interactions).
//!
//! # Events Types
Expand Down Expand Up @@ -53,7 +53,7 @@ use crate::{
},
};

/// Stores the common data needed for all points events.
/// Stores the common data needed for all pointer events.
///
/// The documentation for the [`pointer_events`] explains the events this module exposes and
/// the order in which they fire.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_picking/src/focus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Determines which entities are being hovered by which pointers.
//!
//! The most important type in this module is the [`HoverMap`], which maps points to the entities
//! The most important type in this module is the [`HoverMap`], which maps pointers to the entities
//! they are hovering over.

use std::{
Expand Down
23 changes: 13 additions & 10 deletions crates/bevy_picking/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,27 @@ use crate::PickSet;

/// Common imports for `bevy_picking`.
pub mod prelude {
pub use crate::input::InputPlugin;
pub use crate::input::PointerInputPlugin;
}

/// Adds mouse and touch inputs for picking pointers to your app. This is a default input plugin,
/// that you can replace with your own plugin as needed.
///
/// [`crate::PickingPluginsSettings::is_input_enabled`] can be used to toggle whether
/// [`crate::PickingPlugin::is_input_enabled`] can be used to toggle whether
/// the core picking plugin processes the inputs sent by this, or other input plugins, in one place.
///
/// This plugin contains several settings, and is added to the world as a resource after initalization.

Check warning on line 43 in crates/bevy_picking/src/input.rs

View workflow job for this annotation

GitHub Actions / typos

"initalization" should be "initialization".
/// You can configure pointer input settings at runtime by accessing the resource.
#[derive(Copy, Clone, Resource, Debug, Reflect)]
#[reflect(Resource, Default)]
pub struct InputPlugin {
pub struct PointerInputPlugin {
/// Should touch inputs be updated?
pub is_touch_enabled: bool,
/// Should mouse inputs be updated?
pub is_mouse_enabled: bool,
}

impl InputPlugin {
impl PointerInputPlugin {
fn is_mouse_enabled(state: Res<Self>) -> bool {
state.is_mouse_enabled
}
Expand All @@ -58,7 +61,7 @@ impl InputPlugin {
}
}

impl Default for InputPlugin {
impl Default for PointerInputPlugin {
fn default() -> Self {
Self {
is_touch_enabled: true,
Expand All @@ -67,25 +70,25 @@ impl Default for InputPlugin {
}
}

impl Plugin for InputPlugin {
impl Plugin for PointerInputPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(*self)
.add_systems(Startup, spawn_mouse_pointer)
.add_systems(
First,
(
mouse_pick_events.run_if(InputPlugin::is_mouse_enabled),
touch_pick_events.run_if(InputPlugin::is_touch_enabled),
mouse_pick_events.run_if(PointerInputPlugin::is_mouse_enabled),
touch_pick_events.run_if(PointerInputPlugin::is_touch_enabled),
)
.chain()
.in_set(PickSet::Input),
)
.add_systems(
Last,
deactivate_touch_pointers.run_if(InputPlugin::is_touch_enabled),
deactivate_touch_pointers.run_if(PointerInputPlugin::is_touch_enabled),
)
.register_type::<Self>()
.register_type::<InputPlugin>();
.register_type::<PointerInputPlugin>();
}
}

Expand Down
97 changes: 48 additions & 49 deletions crates/bevy_picking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This crate provides 'picking' capabilities for the bevy game engine. That means, basycally, figuring out
//! This crate provides 'picking' capabilities for the Bevy game engine. That means, in simple terms, figuring out
//! how to connect up a user's clicks or taps to the entities they are trying to interact with.
//!
//! ## Overview
Expand Down Expand Up @@ -164,45 +164,11 @@ use bevy_reflect::prelude::*;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
events::*, input::InputPlugin, pointer::PointerButton, DefaultPickingPlugins,
InteractionPlugin, Pickable, PickingPlugin, PickingPluginsSettings,
events::*, input::PointerInputPlugin, pointer::PointerButton, DefaultPickingPlugins,
InteractionPlugin, Pickable, PickingPlugin,
};
}

/// Used to globally toggle picking features at runtime.
#[derive(Clone, Debug, Resource, Reflect)]
#[reflect(Resource, Default)]
pub struct PickingPluginsSettings {
/// Enables and disables all picking features.
pub is_enabled: bool,
/// Enables and disables input collection.
pub is_input_enabled: bool,
/// Enables and disables updating interaction states of entities.
pub is_focus_enabled: bool,
}

impl PickingPluginsSettings {
/// Whether or not input collection systems should be running.
pub fn input_should_run(state: Res<Self>) -> bool {
state.is_input_enabled && state.is_enabled
}
/// Whether or not systems updating entities' [`PickingInteraction`](focus::PickingInteraction)
/// component should be running.
pub fn focus_should_run(state: Res<Self>) -> bool {
state.is_focus_enabled && state.is_enabled
}
}

impl Default for PickingPluginsSettings {
fn default() -> Self {
Self {
is_enabled: true,
is_input_enabled: true,
is_focus_enabled: true,
}
}
}

/// An optional component that overrides default picking behavior for an entity, allowing you to
/// make an entity non-hoverable, or allow items below it to be hovered. See the documentation on
/// the fields for more details.
Expand Down Expand Up @@ -324,8 +290,9 @@ pub enum PickSet {
Last,
}

/// One plugin that contains the [`input::InputPlugin`], [`PickingPlugin`] and the [`InteractionPlugin`],
/// this is probably the plugin that will be most used.
/// One plugin that contains the [`PointerInputPlugin`](input::PointerInputPlugin), [`PickingPlugin`]
/// and the [`InteractionPlugin`], this is probably the plugin that will be most used.
///
/// Note: for any of these plugins to work, they require a picking backend to be active,
/// The picking backend is responsible to turn an input, into a [`crate::backend::PointerHits`]
/// that [`PickingPlugin`] and [`InteractionPlugin`] will refine into [`bevy_ecs::observer::Trigger`]s.
Expand All @@ -335,21 +302,54 @@ pub struct DefaultPickingPlugins;
impl Plugin for DefaultPickingPlugins {
fn build(&self, app: &mut App) {
app.add_plugins((
input::InputPlugin::default(),
PickingPlugin,
input::PointerInputPlugin::default(),
PickingPlugin::default(),
InteractionPlugin,
));
}
}

/// This plugin sets up the core picking infrastructure. It receives input events, and provides the shared
/// types used by other picking plugins.
#[derive(Default)]
pub struct PickingPlugin;
///
/// This plugin contains several settings, and is added to the wrold as a resource after initalization. You

Check warning on line 315 in crates/bevy_picking/src/lib.rs

View workflow job for this annotation

GitHub Actions / typos

"initalization" should be "initialization".
/// can configure picking settings at runtime through the resource.
#[derive(Copy, Clone, Debug, Resource, Reflect)]
#[reflect(Resource, Default)]
pub struct PickingPlugin {
/// Enables and disables all picking features.
pub is_enabled: bool,
/// Enables and disables input collection.
pub is_input_enabled: bool,
/// Enables and disables updating interaction states of entities.
pub is_focus_enabled: bool,
}

impl PickingPlugin {
/// Whether or not input collection systems should be running.
pub fn input_should_run(state: Res<Self>) -> bool {
state.is_input_enabled && state.is_enabled
}
/// Whether or not systems updating entities' [`PickingInteraction`](focus::PickingInteraction)
/// component should be running.
pub fn focus_should_run(state: Res<Self>) -> bool {
state.is_focus_enabled && state.is_enabled
}
}

impl Default for PickingPlugin {
fn default() -> Self {
Self {
is_enabled: true,
is_input_enabled: true,
is_focus_enabled: true,
}
}
}

impl Plugin for PickingPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<PickingPluginsSettings>()
app.insert_resource(*self)
.init_resource::<pointer::PointerMap>()
.init_resource::<backend::ray::RayMap>()
.add_event::<pointer::PointerInput>()
Expand Down Expand Up @@ -378,22 +378,21 @@ impl Plugin for PickingPlugin {
.configure_sets(
PreUpdate,
(
PickSet::ProcessInput.run_if(PickingPluginsSettings::input_should_run),
PickSet::ProcessInput.run_if(Self::input_should_run),
PickSet::Backend,
PickSet::Focus.run_if(PickingPluginsSettings::focus_should_run),
PickSet::Focus.run_if(Self::focus_should_run),
PickSet::PostFocus,
// Eventually events will need to be dispatched here
PickSet::Last,
)
.ambiguous_with(bevy_asset::handle_internal_asset_events)
.chain(),
)
.register_type::<Self>()
.register_type::<Pickable>()
.register_type::<pointer::PointerId>()
.register_type::<pointer::PointerLocation>()
.register_type::<pointer::PointerPress>()
.register_type::<pointer::PointerInteraction>()
.register_type::<Pickable>()
.register_type::<PickingPluginsSettings>()
.register_type::<backend::ray::RayId>();
}
}
Expand Down

0 comments on commit a3edeaf

Please sign in to comment.