From f15578f7dfb7ff2481abbe9ff89828a620f31ff9 Mon Sep 17 00:00:00 2001 From: Nova Date: Wed, 19 Jul 2023 04:16:32 -0700 Subject: [PATCH] feat: formatting --- src/main.rs | 5 ++- src/objects/play_space.rs | 65 ++++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index 993e93b..bd3067d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -174,7 +174,10 @@ fn main() { sk.input_hand_visible(Handed::Right, false); } - let play_space = sk.world_has_bounds().then(|| PlaySpace::new().ok()).flatten(); + let play_space = sk + .world_has_bounds() + .then(|| PlaySpace::new().ok()) + .flatten(); let (event_stop_tx, event_stop_rx) = oneshot::channel::<()>(); let (info_sender, info_receiver) = oneshot::channel::(); diff --git a/src/objects/play_space.rs b/src/objects/play_space.rs index 9020ed0..664a1d3 100644 --- a/src/objects/play_space.rs +++ b/src/objects/play_space.rs @@ -4,47 +4,70 @@ use color_eyre::eyre::Result; use glam::Mat4; use mint::Vector2; use nanoid::nanoid; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use stereokit::StereoKitMultiThread; -use crate::{nodes::{spatial::Spatial, data::{PulseReceiver, Mask}, Node, fields::{Field, r#box::BoxField}}, core::client::INTERNAL_CLIENT}; +use crate::{ + core::client::INTERNAL_CLIENT, + nodes::{ + data::{Mask, PulseReceiver}, + fields::{r#box::BoxField, Field}, + spatial::Spatial, + Node, + }, +}; #[derive(Debug, Deserialize, Serialize)] struct PlaySpaceMap { - play_space: (), - size: Vector2, + play_space: (), + size: Vector2, } impl Default for PlaySpaceMap { - fn default() -> Self { - Self { play_space: (), size: [0.0; 2].into() } - } + fn default() -> Self { + Self { + play_space: (), + size: [0.0; 2].into(), + } + } } pub struct PlaySpace { - _node: Arc, - spatial: Arc, - field: Arc, - _pulse_rx: Arc, + _node: Arc, + spatial: Arc, + field: Arc, + _pulse_rx: Arc, } impl PlaySpace { pub fn new() -> Result { let node = Node::create(&INTERNAL_CLIENT, "", &nanoid!(), false).add_to_scenegraph()?; let spatial = Spatial::add_to(&node, None, Mat4::IDENTITY, false)?; - let field = BoxField::add_to(&node, [0.0;3].into())?; + let field = BoxField::add_to(&node, [0.0; 3].into())?; - let pulse_rx = PulseReceiver::add_to(&node, field.clone(), Mask::from_struct::())?; + let pulse_rx = + PulseReceiver::add_to(&node, field.clone(), Mask::from_struct::())?; Ok(PlaySpace { _node: node, spatial, - field, + field, _pulse_rx: pulse_rx, }) } - pub fn update(&self, sk: &impl StereoKitMultiThread) { - let pose = sk.world_get_bounds_pose(); - self.spatial.set_local_transform(Mat4::from_rotation_translation(pose.orientation, pose.position)); - let Field::Box(box_field) = self.field.as_ref() else {return}; - box_field.set_size([sk.world_get_bounds_size().x, 0.0, sk.world_get_bounds_size().y].into()); - } -} \ No newline at end of file + pub fn update(&self, sk: &impl StereoKitMultiThread) { + let pose = sk.world_get_bounds_pose(); + self.spatial + .set_local_transform(Mat4::from_rotation_translation( + pose.orientation, + pose.position, + )); + let Field::Box(box_field) = self.field.as_ref() else {return}; + box_field.set_size( + [ + sk.world_get_bounds_size().x, + 0.0, + sk.world_get_bounds_size().y, + ] + .into(), + ); + } +}