refactor(items): genericize item acceptors/ui
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
use super::{Item, ItemSpecialization, ItemType, ITEM_TYPE_INFO_ENVIRONMENT};
|
use super::{Item, ItemSpecialization, ItemType};
|
||||||
use crate::{
|
use crate::{
|
||||||
core::client::{Client, INTERNAL_CLIENT},
|
core::{
|
||||||
|
client::{Client, INTERNAL_CLIENT},
|
||||||
|
registry::Registry,
|
||||||
|
},
|
||||||
nodes::{
|
nodes::{
|
||||||
|
items::TypeInfo,
|
||||||
spatial::{find_spatial_parent, parse_transform, Spatial},
|
spatial::{find_spatial_parent, parse_transform, Spatial},
|
||||||
Node,
|
Node,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use stardust_xr::{
|
use stardust_xr::{
|
||||||
schemas::flex::{deserialize, serialize},
|
schemas::flex::{deserialize, serialize},
|
||||||
@@ -14,6 +19,18 @@ use stardust_xr::{
|
|||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub(super) static ref ITEM_TYPE_INFO_ENVIRONMENT: TypeInfo = TypeInfo {
|
||||||
|
type_name: "environment",
|
||||||
|
aliased_local_signals: vec!["apply_sky_tex", "apply_sky_light"],
|
||||||
|
aliased_local_methods: vec![],
|
||||||
|
aliased_remote_signals: vec![],
|
||||||
|
ui: Default::default(),
|
||||||
|
items: Registry::new(),
|
||||||
|
acceptors: Registry::new(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub struct EnvironmentItem {
|
pub struct EnvironmentItem {
|
||||||
path: String,
|
path: String,
|
||||||
}
|
}
|
||||||
@@ -67,19 +84,3 @@ pub(super) fn create_environment_item_flex(
|
|||||||
.make_alias(&calling_client, &parent_name);
|
.make_alias(&calling_client, &parent_name);
|
||||||
Ok(())
|
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)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
mod environment;
|
mod environment;
|
||||||
|
|
||||||
use self::environment::EnvironmentItem;
|
use self::environment::{EnvironmentItem, ITEM_TYPE_INFO_ENVIRONMENT};
|
||||||
use super::fields::Field;
|
use super::fields::Field;
|
||||||
use super::spatial::{find_spatial_parent, parse_transform, Spatial};
|
use super::spatial::{find_spatial_parent, parse_transform, Spatial};
|
||||||
use super::{Alias, Node};
|
use super::{Alias, Node};
|
||||||
@@ -9,7 +9,7 @@ use crate::core::node_collections::LifeLinkedNodeList;
|
|||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::nodes::alias::AliasInfo;
|
use crate::nodes::alias::AliasInfo;
|
||||||
use crate::nodes::fields::find_field;
|
use crate::nodes::fields::find_field;
|
||||||
use crate::wayland::panel_item::{register_panel_item_ui_flex, PanelItem};
|
use crate::wayland::panel_item::{PanelItem, ITEM_TYPE_INFO_PANEL};
|
||||||
use anyhow::{anyhow, ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
@@ -33,15 +33,6 @@ lazy_static! {
|
|||||||
static ref ITEM_ALIAS_LOCAL_METHODS: Vec<&'static str> = vec!["capture_into"];
|
static ref ITEM_ALIAS_LOCAL_METHODS: Vec<&'static str> = vec!["capture_into"];
|
||||||
static ref ITEM_ALIAS_REMOTE_SIGNALS: Vec<&'static str> = vec![];
|
static ref ITEM_ALIAS_REMOTE_SIGNALS: Vec<&'static str> = vec![];
|
||||||
static ref ITEM_ALIAS_REMOTE_METHODS: Vec<&'static str> = vec![];
|
static ref ITEM_ALIAS_REMOTE_METHODS: Vec<&'static str> = vec![];
|
||||||
static ref ITEM_TYPE_INFO_ENVIRONMENT: TypeInfo = TypeInfo {
|
|
||||||
type_name: "environment",
|
|
||||||
aliased_local_signals: vec!["apply_sky_tex", "apply_sky_light"],
|
|
||||||
aliased_local_methods: vec![],
|
|
||||||
aliased_remote_signals: vec![],
|
|
||||||
ui: Default::default(),
|
|
||||||
items: Registry::new(),
|
|
||||||
acceptors: Registry::new(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture(item: &Arc<Item>, acceptor: &Arc<ItemAcceptor>) {
|
fn capture(item: &Arc<Item>, acceptor: &Arc<ItemAcceptor>) {
|
||||||
@@ -326,35 +317,34 @@ pub fn create_interface(client: &Arc<Client>) {
|
|||||||
"create_environment_item",
|
"create_environment_item",
|
||||||
environment::create_environment_item_flex,
|
environment::create_environment_item_flex,
|
||||||
);
|
);
|
||||||
node.add_local_signal(
|
node.add_local_signal("register_item_ui", register_item_ui_flex);
|
||||||
"register_environment_item_ui",
|
node.add_local_signal("create_item_acceptor", create_item_acceptor_flex);
|
||||||
environment::register_environment_item_ui_flex,
|
|
||||||
);
|
|
||||||
node.add_local_signal("register_panel_item_ui", register_panel_item_ui_flex);
|
|
||||||
node.add_local_signal(
|
|
||||||
"create_environment_item_acceptor",
|
|
||||||
environment::create_environment_item_acceptor_flex,
|
|
||||||
);
|
|
||||||
node.add_to_scenegraph();
|
node.add_to_scenegraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(self) fn create_item_acceptor_flex(
|
fn type_info(name: &str) -> Result<&'static TypeInfo> {
|
||||||
calling_client: Arc<Client>,
|
match name {
|
||||||
data: &[u8],
|
"environment" => Ok(&ITEM_TYPE_INFO_ENVIRONMENT),
|
||||||
type_info: &'static TypeInfo,
|
"panel" => Ok(&ITEM_TYPE_INFO_PANEL),
|
||||||
) -> Result<()> {
|
_ => Err(anyhow!("Invalid item type")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_item_acceptor_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct CreateItemAcceptorInfo<'a> {
|
struct CreateItemAcceptorInfo<'a> {
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
parent_path: &'a str,
|
parent_path: &'a str,
|
||||||
transform: Transform,
|
transform: Transform,
|
||||||
field_path: &'a str,
|
field_path: &'a str,
|
||||||
|
item_type: &'a str,
|
||||||
}
|
}
|
||||||
let info: CreateItemAcceptorInfo = deserialize(data)?;
|
let info: CreateItemAcceptorInfo = deserialize(data)?;
|
||||||
let parent_name = format!("/item/{}/acceptor/", ITEM_TYPE_INFO_ENVIRONMENT.type_name);
|
let parent_name = format!("/item/{}/acceptor/", ITEM_TYPE_INFO_ENVIRONMENT.type_name);
|
||||||
let space = find_spatial_parent(&calling_client, info.parent_path)?;
|
let space = find_spatial_parent(&calling_client, info.parent_path)?;
|
||||||
let transform = parse_transform(info.transform, true, true, false)?;
|
let transform = parse_transform(info.transform, true, true, false)?;
|
||||||
let field = find_field(&calling_client, info.field_path)?;
|
let field = find_field(&calling_client, info.field_path)?;
|
||||||
|
let type_info = type_info(info.item_type)?;
|
||||||
|
|
||||||
let node = Node::create(&INTERNAL_CLIENT, &parent_name, info.name, true).add_to_scenegraph();
|
let node = Node::create(&INTERNAL_CLIENT, &parent_name, info.name, true).add_to_scenegraph();
|
||||||
Spatial::add_to(&node, Some(space), transform, false)?;
|
Spatial::add_to(&node, Some(space), transform, false)?;
|
||||||
@@ -366,10 +356,13 @@ pub(self) fn create_item_acceptor_flex(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_item_ui_flex(
|
pub fn register_item_ui_flex(_node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
calling_client: Arc<Client>,
|
#[derive(Deserialize)]
|
||||||
type_info: &'static TypeInfo,
|
struct RegisterItemUIInfo<'a> {
|
||||||
) -> Result<()> {
|
item_type: &'a str,
|
||||||
|
}
|
||||||
|
let info: RegisterItemUIInfo = deserialize(data)?;
|
||||||
|
let type_info = type_info(info.item_type)?;
|
||||||
let ui = Node::create(&calling_client, "/item", type_info.type_name, true).add_to_scenegraph();
|
let ui = Node::create(&calling_client, "/item", type_info.type_name, true).add_to_scenegraph();
|
||||||
ItemUI::add_to(&ui, type_info)?;
|
ItemUI::add_to(&ui, type_info)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
registry::Registry,
|
registry::Registry,
|
||||||
},
|
},
|
||||||
nodes::{
|
nodes::{
|
||||||
items::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
|
items::{Item, ItemSpecialization, ItemType, TypeInfo},
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
Node,
|
Node,
|
||||||
},
|
},
|
||||||
@@ -29,7 +29,7 @@ use std::sync::{Arc, Weak};
|
|||||||
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keymap};
|
use xkbcommon::xkb::{self, ffi::XKB_KEYMAP_FORMAT_TEXT_V1, Keymap};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref ITEM_TYPE_INFO_PANEL: TypeInfo = TypeInfo {
|
pub static ref ITEM_TYPE_INFO_PANEL: TypeInfo = TypeInfo {
|
||||||
type_name: "panel",
|
type_name: "panel",
|
||||||
aliased_local_signals: vec![
|
aliased_local_signals: vec![
|
||||||
"apply_surface_material",
|
"apply_surface_material",
|
||||||
@@ -498,11 +498,3 @@ impl ItemSpecialization for PanelItem {
|
|||||||
serialize((id, (panel_size, cursor_size.zip(cursor_hotspot)))).unwrap()
|
serialize((id, (panel_size, cursor_size.zip(cursor_hotspot)))).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_panel_item_ui_flex(
|
|
||||||
_node: &Node,
|
|
||||||
calling_client: Arc<Client>,
|
|
||||||
_data: &[u8],
|
|
||||||
) -> Result<()> {
|
|
||||||
register_item_ui_flex(calling_client, &ITEM_TYPE_INFO_PANEL)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user