refactor: make all flex stuff use serde
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
use super::{Item, ItemSpecialization, ItemType, ITEM_TYPE_INFO_ENVIRONMENT};
|
||||
use crate::{core::client::Client, nodes::Node};
|
||||
use crate::{
|
||||
core::client::{Client, INTERNAL_CLIENT},
|
||||
nodes::{
|
||||
spatial::{get_spatial_parent_flex, parse_transform, Spatial},
|
||||
Node,
|
||||
},
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use serde::Deserialize;
|
||||
use stardust_xr::{
|
||||
schemas::flex::{deserialize, serialize},
|
||||
values::Transform,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct EnvironmentItem {
|
||||
@@ -25,7 +36,50 @@ impl EnvironmentItem {
|
||||
}
|
||||
}
|
||||
impl ItemSpecialization for EnvironmentItem {
|
||||
fn serialize_start_data(&self, vec: &mut flexbuffers::VectorBuilder) {
|
||||
vec.push(self.path.as_str());
|
||||
fn serialize_start_data(&self, id: &str) -> Vec<u8> {
|
||||
serialize((id, self.path.as_str())).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn create_environment_item_flex(
|
||||
_node: &Node,
|
||||
calling_client: Arc<Client>,
|
||||
data: &[u8],
|
||||
) -> Result<()> {
|
||||
#[derive(Deserialize)]
|
||||
struct CreateEnvironmentItemInfo<'a> {
|
||||
name: &'a str,
|
||||
parent_path: &'a str,
|
||||
transform: Transform,
|
||||
item_data: String,
|
||||
}
|
||||
let info: CreateEnvironmentItemInfo = deserialize(data)?;
|
||||
let parent_name = format!("/item/{}/item/", ITEM_TYPE_INFO_ENVIRONMENT.type_name);
|
||||
let node = Node::create(&INTERNAL_CLIENT, &parent_name, info.name, true);
|
||||
let space = get_spatial_parent_flex(&calling_client, info.parent_path)?;
|
||||
let transform = parse_transform(info.transform, true, true, false)?;
|
||||
let node = node.add_to_scenegraph();
|
||||
Spatial::add_to(&node, None, transform * space.global_transform())?;
|
||||
EnvironmentItem::add_to(&node, info.item_data);
|
||||
node.item
|
||||
.get()
|
||||
.unwrap()
|
||||
.make_alias(&calling_client, &parent_name);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn create_environment_item_acceptor_flex(
|
||||
_node: &Node,
|
||||
calling_client: Arc<Client>,
|
||||
data: &[u8],
|
||||
) -> Result<()> {
|
||||
super::create_item_acceptor_flex(calling_client, data, &ITEM_TYPE_INFO_ENVIRONMENT)
|
||||
}
|
||||
|
||||
pub(super) fn register_environment_item_ui_flex(
|
||||
_node: &Node,
|
||||
calling_client: Arc<Client>,
|
||||
_data: &[u8],
|
||||
) -> Result<()> {
|
||||
super::register_item_ui_flex(calling_client, &ITEM_TYPE_INFO_ENVIRONMENT)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user