Skip to content

Commit

Permalink
feat: update to new molecules
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Jul 3, 2024
1 parent 1493f8c commit c433f5b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions src/close_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use stardust_xr_fusion::{
spatial::{SpatialAspect, Transform},
};
use stardust_xr_molecules::{
input_action::{InputQueue, InputQueueable, MultiActorAction},
input_action::{InputQueue, InputQueueable, SimpleAction},
Exposure,
};

Expand All @@ -21,7 +21,7 @@ pub struct CloseButton {
exposure: Exposure,
field: Field,
input: InputQueue,
distance_action: MultiActorAction,
distance_action: SimpleAction,
}
impl CloseButton {
pub fn new(item: PanelItem, thickness: f32, surface: &Surface) -> Result<Self, NodeError> {
Expand Down Expand Up @@ -50,7 +50,6 @@ impl CloseButton {
field.set_local_transform(Transform::from_scale([1.0; 3]))?;

let input = InputHandler::create(&shell, Transform::none(), &field)?.queue()?;
let interact_action = MultiActorAction::default();

Ok(CloseButton {
item,
Expand All @@ -59,12 +58,12 @@ impl CloseButton {
exposure,
field,
input,
distance_action: interact_action,
distance_action: SimpleAction::default(),
})
}

pub fn update(&mut self, frame_info: &FrameInfo) {
self.distance_action.update(true, &self.input, |data| {
self.distance_action.update(&self.input, &|data| {
data.distance < 0.0
&& match &data.input {
Pointer(_) => data.datamap.with_data(|d| d.idx("select").as_f32() > 0.5),
Expand All @@ -81,7 +80,7 @@ impl CloseButton {
self.exposure
.expose(exposure * 2.0 / TOPLEVEL_THICKNESS, frame_info.delta as f32);
self.exposure
.expose_flash(self.distance_action.started_acting().len() as f32 * 0.25);
.expose_flash(self.distance_action.currently_acting().len() as f32 * 0.25);
if self.exposure.exposure > 1.0 {
let _ = self.item.close_toplevel();
} else if self.exposure.exposure > 0.0 {
Expand Down
10 changes: 5 additions & 5 deletions src/grab_ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use stardust_xr_fusion::{
node::{NodeError, NodeType},
spatial::{Spatial, SpatialAspect, Transform},
};
use stardust_xr_molecules::input_action::{InputQueue, InputQueueable, SingleActorAction};
use stardust_xr_molecules::input_action::{InputQueue, InputQueueable, SingleAction};

pub trait GrabBallHead {
fn root(&self) -> &impl SpatialAspect;
fn set_enabled(&mut self, enabled: bool);
fn update(&mut self, grab_action: &SingleActorAction);
fn update(&mut self, grab_action: &SingleAction);
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct GrabBall<H: GrabBallHead> {
_field: Field,
settings: GrabBallSettings,
input: InputQueue,
grab_action: SingleActorAction,
grab_action: SingleAction,
}
impl<H: GrabBallHead> GrabBall<H> {
pub fn create(
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<H: GrabBallHead> GrabBall<H> {
let input_handler =
InputHandler::create(&connect_root, Transform::none(), &_field)?.queue()?;

let grab_action = SingleActorAction::default();
let grab_action = SingleAction::default();

Ok(GrabBall {
connect_root,
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<H: GrabBallHead> GrabBall<H> {
&self.connect_root
}

pub fn grab_action(&self) -> &SingleActorAction {
pub fn grab_action(&self) -> &SingleAction {
&self.grab_action
}
}
6 changes: 3 additions & 3 deletions src/panel_shell_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use stardust_xr_fusion::{
node::{NodeError, NodeType},
spatial::{SpatialAspect, Transform},
};
use stardust_xr_molecules::input_action::SingleActorAction;
use stardust_xr_molecules::input_action::SingleAction;
use tokio::task::JoinSet;

use crate::grab_ball::GrabBallHead;
Expand Down Expand Up @@ -40,7 +40,7 @@ impl PanelShellTransfer {

pub fn update_distances(
&self,
grab_action: &SingleActorAction,
grab_action: &SingleAction,
acceptors: &FxHashMap<u64, (PanelItemAcceptor, Field)>,
) {
let mut fields: JoinSet<Result<(f32, PanelItemAcceptor), NodeError>> = JoinSet::new();
Expand Down Expand Up @@ -102,5 +102,5 @@ impl GrabBallHead for PanelShellTransfer {
let _ = self.model.set_enabled(enabled);
}

fn update(&mut self, _grab_action: &SingleActorAction) {}
fn update(&mut self, _grab_action: &SingleAction) {}
}
23 changes: 14 additions & 9 deletions src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ impl Surface {
// set pointer position with the closest thing that's hovering
if let Some(closest_hover) = self
.hover_plane
.hovering_inputs()
.into_iter()
.chain(self.hover_plane.interact_status().actor().cloned())
.hovering()
.current()
.iter()
.chain(self.hover_plane.interact_status().actor())
.reduce(|a, b| if a.distance > b.distance { b } else { a })
{
let (interact_point, _depth) = self.hover_plane.interact_point(&closest_hover);
Expand All @@ -165,9 +166,10 @@ impl Surface {

for input in self
.hover_plane
.hovering_inputs()
.into_iter()
.chain(self.hover_plane.interact_status().actor().cloned())
.hovering()
.current()
.iter()
.chain(self.hover_plane.interact_status().actor())
{
let mouse_event = input
.datamap
Expand Down Expand Up @@ -195,7 +197,8 @@ impl Surface {
// proper touches
for input_data in self
.touch_plane
.touching()
.action()
.interact()
.added()
.into_iter()
.filter(Self::filter_touch)
Expand All @@ -208,7 +211,8 @@ impl Surface {
}
for input_data in self
.touch_plane
.touching()
.action()
.interact()
.current()
.into_iter()
.filter(Self::filter_touch)
Expand All @@ -221,7 +225,8 @@ impl Surface {
}
for input_data in self
.touch_plane
.touching()
.action()
.interact()
.removed()
.into_iter()
.filter(Self::filter_touch)
Expand Down

0 comments on commit c433f5b

Please sign in to comment.