Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some reflections #376

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/bevy_picking_core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ pub mod ray {
/// }
/// }
/// ```
#[derive(Clone, Debug, Default, Resource)]
#[derive(Clone, Debug, Default, Resource, Reflect)]
#[reflect(Resource)]
pub struct RayMap {
map: HashMap<RayId, Ray3d>,
}
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_picking_core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,12 @@ pub fn pointer_events(
}

/// Maps pointers to the entities they are dragging.
#[derive(Debug, Deref, DerefMut, Default, Resource)]
#[derive(Debug, Deref, DerefMut, Default, Resource, Reflect)]
#[reflect(Resource)]
pub struct DragMap(pub HashMap<(PointerId, PointerButton), HashMap<Entity, DragEntry>>);

/// An entry in the [`DragMap`].
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Reflect)]
pub struct DragEntry {
/// The position of the pointer at drag start.
pub start_pos: Vec2,
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_picking_core/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ type OverMap = HashMap<PointerId, LayerMap>;
/// this authoritative hover state, and you can do the same. You can also use the
/// [`PreviousHoverMap`] as a robust way of determining changes in hover state from the previous
/// update.
#[derive(Debug, Deref, DerefMut, Default, Resource)]
#[derive(Debug, Deref, DerefMut, Default, Resource, Reflect)]
#[reflect(Resource)]
pub struct HoverMap(pub HashMap<PointerId, HashMap<Entity, HitData>>);

/// The previous state of the hover map, used to track changes to hover state.
#[derive(Debug, Deref, DerefMut, Default, Resource)]
#[derive(Debug, Deref, DerefMut, Default, Resource, Reflect)]
#[reflect(Resource)]
pub struct PreviousHoverMap(pub HashMap<PointerId, HashMap<Entity, HitData>>);

/// Coalesces all data from inputs and backends to generate a map of the currently hovered entities.
Expand Down
11 changes: 9 additions & 2 deletions crates/bevy_picking_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;

use bevy_eventlistener::{prelude::*, EventListenerSet};
use focus::{HoverMap, PreviousHoverMap};
/// Used to globally toggle picking features at runtime.
#[derive(Clone, Debug, Resource, Reflect)]
#[reflect(Resource, Default)]
Expand Down Expand Up @@ -208,11 +209,14 @@ impl Plugin for CorePlugin {
)
.register_type::<pointer::PointerId>()
.register_type::<pointer::PointerLocation>()
.register_type::<pointer::Location>()
.register_type::<pointer::PointerPress>()
.register_type::<pointer::PointerInteraction>()
.register_type::<pointer::PointerMap>()
.register_type::<Pickable>()
.register_type::<PickingPluginsSettings>()
.register_type::<backend::ray::RayId>();
.register_type::<backend::ray::RayId>()
.register_type::<backend::ray::RayMap>();
}
}

Expand Down Expand Up @@ -253,6 +257,9 @@ impl Plugin for InteractionPlugin {
EventListenerPlugin::<Pointer<DragOver>>::default(),
EventListenerPlugin::<Pointer<DragLeave>>::default(),
EventListenerPlugin::<Pointer<Drop>>::default(),
));
))
.register_type::<HoverMap>()
.register_type::<PreviousHoverMap>()
.register_type::<DragMap>();
}
}
5 changes: 3 additions & 2 deletions crates/bevy_picking_core/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ impl Deref for PointerInteraction {
}

/// A resource that maps each [`PointerId`] to their [`Entity`] for easy lookups.
#[derive(Debug, Clone, Default, Resource)]
#[derive(Debug, Clone, Default, Resource, Reflect)]
#[reflect(Resource)]
pub struct PointerMap {
inner: HashMap<PointerId, Entity>,
}
Expand Down Expand Up @@ -225,7 +226,6 @@ impl PointerButton {
pub struct PointerLocation {
/// The [`Location`] of the pointer. Note that a location is both the target, and the position
/// on the target.
#[reflect(ignore)]
pub location: Option<Location>,
}
impl PointerLocation {
Expand Down Expand Up @@ -280,6 +280,7 @@ impl InputMove {
/// render target. It is up to picking backends to associate a Pointer's `Location` with a
/// specific `Camera`, if any.
#[derive(Debug, Clone, Component, Reflect, PartialEq)]
#[reflect(Component)]
pub struct Location {
/// The [`NormalizedRenderTarget`] associated with the pointer, usually a window.
pub target: NormalizedRenderTarget,
Expand Down
Loading