refactor(items): environment submodule
This commit is contained in:
@@ -4,7 +4,7 @@ use crate::nodes::data;
|
|||||||
use crate::nodes::field;
|
use crate::nodes::field;
|
||||||
use crate::nodes::hmd;
|
use crate::nodes::hmd;
|
||||||
use crate::nodes::input;
|
use crate::nodes::input;
|
||||||
use crate::nodes::item;
|
use crate::nodes::items;
|
||||||
use crate::nodes::model;
|
use crate::nodes::model;
|
||||||
use crate::nodes::root::Root;
|
use crate::nodes::root::Root;
|
||||||
use crate::nodes::spatial;
|
use crate::nodes::spatial;
|
||||||
@@ -73,7 +73,7 @@ impl Client {
|
|||||||
field::create_interface(&client);
|
field::create_interface(&client);
|
||||||
model::create_interface(&client);
|
model::create_interface(&client);
|
||||||
data::create_interface(&client);
|
data::create_interface(&client);
|
||||||
item::create_interface(&client);
|
items::create_interface(&client);
|
||||||
input::create_interface(&client);
|
input::create_interface(&client);
|
||||||
|
|
||||||
let _ = client.join_handle.set(tokio::spawn({
|
let _ = client.join_handle.set(tokio::spawn({
|
||||||
|
|||||||
31
src/nodes/items/environment.rs
Normal file
31
src/nodes/items/environment.rs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
mod environment;
|
||||||
|
|
||||||
|
use self::environment::EnvironmentItem;
|
||||||
|
|
||||||
use super::field::Field;
|
use super::field::Field;
|
||||||
use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial};
|
use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial};
|
||||||
use super::{Alias, Node};
|
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 {
|
pub struct ItemUI {
|
||||||
node: Weak<Node>,
|
node: Weak<Node>,
|
||||||
type_info: &'static TypeInfo,
|
type_info: &'static TypeInfo,
|
||||||
@@ -3,7 +3,7 @@ pub mod data;
|
|||||||
pub mod field;
|
pub mod field;
|
||||||
pub mod hmd;
|
pub mod hmd;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod item;
|
pub mod items;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
pub mod root;
|
pub mod root;
|
||||||
pub mod spatial;
|
pub mod spatial;
|
||||||
@@ -27,7 +27,7 @@ use self::alias::Alias;
|
|||||||
use self::data::{PulseReceiver, PulseSender};
|
use self::data::{PulseReceiver, PulseSender};
|
||||||
use self::field::Field;
|
use self::field::Field;
|
||||||
use self::input::{InputHandler, InputMethod};
|
use self::input::{InputHandler, InputMethod};
|
||||||
use self::item::{Item, ItemAcceptor, ItemUI};
|
use self::items::{Item, ItemAcceptor, ItemUI};
|
||||||
use self::model::Model;
|
use self::model::Model;
|
||||||
use self::spatial::Spatial;
|
use self::spatial::Spatial;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
registry::Registry,
|
registry::Registry,
|
||||||
},
|
},
|
||||||
nodes::{
|
nodes::{
|
||||||
item::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
|
items::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
Node,
|
Node,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use super::{state::WaylandState, surface::CoreSurface, GLOBAL_DESTROY_QUEUE};
|
use super::{state::WaylandState, surface::CoreSurface, GLOBAL_DESTROY_QUEUE};
|
||||||
use crate::nodes::item::Item;
|
use crate::nodes::items::Item;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
|
|||||||
Reference in New Issue
Block a user