refactor(items): environment submodule

This commit is contained in:
Nova
2022-09-14 22:39:15 -04:00
parent 8c3c211162
commit e492e15013
6 changed files with 41 additions and 33 deletions

View File

@@ -4,7 +4,7 @@ use crate::nodes::data;
use crate::nodes::field;
use crate::nodes::hmd;
use crate::nodes::input;
use crate::nodes::item;
use crate::nodes::items;
use crate::nodes::model;
use crate::nodes::root::Root;
use crate::nodes::spatial;
@@ -73,7 +73,7 @@ impl Client {
field::create_interface(&client);
model::create_interface(&client);
data::create_interface(&client);
item::create_interface(&client);
items::create_interface(&client);
input::create_interface(&client);
let _ = client.join_handle.set(tokio::spawn({

View File

@@ -0,0 +1,31 @@
use super::{Item, ItemSpecialization, ItemType, ITEM_TYPE_INFO_ENVIRONMENT};
use crate::{core::client::Client, nodes::Node};
use anyhow::{anyhow, Result};
use std::sync::Arc;
pub struct EnvironmentItem {
path: String,
}
impl EnvironmentItem {
pub fn add_to(node: &Arc<Node>, path: String) {
Item::add_to(
node,
&ITEM_TYPE_INFO_ENVIRONMENT,
ItemType::Environment(EnvironmentItem { path }),
);
node.add_local_method("getPath", EnvironmentItem::get_path_flex);
}
fn get_path_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<Vec<u8>> {
let path: Result<String> = match &node.item.get().unwrap().specialization {
ItemType::Environment(env) => Ok(env.path.clone()),
_ => Err(anyhow!("")),
};
Ok(flexbuffers::singleton(path?.as_str()))
}
}
impl ItemSpecialization for EnvironmentItem {
fn serialize_start_data(&self, vec: &mut flexbuffers::VectorBuilder) {
vec.push(self.path.as_str());
}
}

View File

@@ -1,3 +1,7 @@
mod environment;
use self::environment::EnvironmentItem;
use super::field::Field;
use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial};
use super::{Alias, Node};
@@ -169,33 +173,6 @@ impl Deref for ItemType {
}
}
pub struct EnvironmentItem {
path: String,
}
impl EnvironmentItem {
pub fn add_to(node: &Arc<Node>, path: String) {
Item::add_to(
node,
&ITEM_TYPE_INFO_ENVIRONMENT,
ItemType::Environment(EnvironmentItem { path }),
);
node.add_local_method("getPath", EnvironmentItem::get_path_flex);
}
fn get_path_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<Vec<u8>> {
let path: Result<String> = match &node.item.get().unwrap().specialization {
ItemType::Environment(env) => Ok(env.path.clone()),
_ => Err(anyhow!("")),
};
Ok(flexbuffers::singleton(path?.as_str()))
}
}
impl ItemSpecialization for EnvironmentItem {
fn serialize_start_data(&self, vec: &mut flexbuffers::VectorBuilder) {
vec.push(self.path.as_str());
}
}
pub struct ItemUI {
node: Weak<Node>,
type_info: &'static TypeInfo,

View File

@@ -3,7 +3,7 @@ pub mod data;
pub mod field;
pub mod hmd;
pub mod input;
pub mod item;
pub mod items;
pub mod model;
pub mod root;
pub mod spatial;
@@ -27,7 +27,7 @@ use self::alias::Alias;
use self::data::{PulseReceiver, PulseSender};
use self::field::Field;
use self::input::{InputHandler, InputMethod};
use self::item::{Item, ItemAcceptor, ItemUI};
use self::items::{Item, ItemAcceptor, ItemUI};
use self::model::Model;
use self::spatial::Spatial;

View File

@@ -8,7 +8,7 @@ use crate::{
registry::Registry,
},
nodes::{
item::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
items::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
spatial::Spatial,
Node,
},

View File

@@ -1,5 +1,5 @@
use super::{state::WaylandState, surface::CoreSurface, GLOBAL_DESTROY_QUEUE};
use crate::nodes::item::Item;
use crate::nodes::items::Item;
use anyhow::Result;
use mint::Vector2;
use nanoid::nanoid;