fix(node): get client returns option
This commit is contained in:
@@ -62,7 +62,14 @@ impl Model {
|
|||||||
let _ = model_arc.pending_model_path.set(
|
let _ = model_arc.pending_model_path.set(
|
||||||
model_arc
|
model_arc
|
||||||
.resource_id
|
.resource_id
|
||||||
.get_file(&node.get_client().base_resource_prefixes.lock().clone())
|
.get_file(
|
||||||
|
&node
|
||||||
|
.get_client()
|
||||||
|
.ok_or_else(|| anyhow!("Client not found"))?
|
||||||
|
.base_resource_prefixes
|
||||||
|
.lock()
|
||||||
|
.clone(),
|
||||||
|
)
|
||||||
.ok_or_else(|| anyhow!("Resource not found"))?,
|
.ok_or_else(|| anyhow!("Resource not found"))?,
|
||||||
);
|
);
|
||||||
let _ = node.model.set(model_arc.clone());
|
let _ = node.model.set(model_arc.clone());
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
Node,
|
Node,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{anyhow, ensure, Result};
|
||||||
use glam::{vec3, Mat4, Vec2};
|
use glam::{vec3, Mat4, Vec2};
|
||||||
use mint::Vector2;
|
use mint::Vector2;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@@ -63,11 +63,13 @@ impl Text {
|
|||||||
"Internal: Node already has text attached!"
|
"Internal: Node already has text attached!"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let client = node
|
||||||
|
.get_client()
|
||||||
|
.ok_or_else(|| anyhow!("Client not found"))?;
|
||||||
let text = TEXT_REGISTRY.add(Text {
|
let text = TEXT_REGISTRY.add(Text {
|
||||||
space: node.spatial.get().unwrap().clone(),
|
space: node.spatial.get().unwrap().clone(),
|
||||||
font_path: font_resource_id.and_then(|res| {
|
font_path: font_resource_id
|
||||||
res.get_file(&node.get_client().base_resource_prefixes.lock().clone())
|
.and_then(|res| res.get_file(&client.base_resource_prefixes.lock().clone())),
|
||||||
}),
|
|
||||||
style: OnceCell::new(),
|
style: OnceCell::new(),
|
||||||
|
|
||||||
data: Mutex::new(TextData {
|
data: Mutex::new(TextData {
|
||||||
|
|||||||
@@ -211,14 +211,16 @@ impl ItemUI {
|
|||||||
|
|
||||||
fn handle_create_item(&self, item: &Item) {
|
fn handle_create_item(&self, item: &Item) {
|
||||||
let node = self.node.upgrade().unwrap();
|
let node = self.node.upgrade().unwrap();
|
||||||
let (alias_node, _) =
|
if let Some(client) = node.get_client() {
|
||||||
item.make_alias(&node.get_client(), &(node.get_path().to_string() + "/item"));
|
let (alias_node, _) =
|
||||||
self.aliases.add(Arc::downgrade(&alias_node));
|
item.make_alias(&client, &(node.get_path().to_string() + "/item"));
|
||||||
|
self.aliases.add(Arc::downgrade(&alias_node));
|
||||||
|
|
||||||
let _ = node.send_remote_signal(
|
let _ = node.send_remote_signal(
|
||||||
"create",
|
"create",
|
||||||
&item.specialization.serialize_start_data(&item.uid),
|
&item.specialization.serialize_start_data(&item.uid),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn handle_destroy_item(&self, item: &Item) {
|
fn handle_destroy_item(&self, item: &Item) {
|
||||||
self.send_state("destroy", item.uid.as_str());
|
self.send_state("destroy", item.uid.as_str());
|
||||||
@@ -231,13 +233,15 @@ impl ItemUI {
|
|||||||
}
|
}
|
||||||
fn handle_create_acceptor(&self, acceptor: &ItemAcceptor) {
|
fn handle_create_acceptor(&self, acceptor: &ItemAcceptor) {
|
||||||
let node = self.node.upgrade().unwrap();
|
let node = self.node.upgrade().unwrap();
|
||||||
let aliases = acceptor.make_aliases(
|
if let Some(client) = node.get_client() {
|
||||||
&node.get_client(),
|
let aliases = acceptor.make_aliases(
|
||||||
&format!("/item/{}/acceptor", self.type_info.type_name),
|
&client,
|
||||||
);
|
&format!("/item/{}/acceptor", self.type_info.type_name),
|
||||||
aliases
|
);
|
||||||
.iter()
|
aliases
|
||||||
.for_each(|alias| self.aliases.add(Arc::downgrade(alias)));
|
.iter()
|
||||||
|
.for_each(|alias| self.aliases.add(Arc::downgrade(alias)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn handle_destroy_acceptor(&self, _acceptor: &ItemAcceptor) {}
|
fn handle_destroy_acceptor(&self, _acceptor: &ItemAcceptor) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ pub struct Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
pub fn get_client(&self) -> Arc<Client> {
|
pub fn get_client(&self) -> Option<Arc<Client>> {
|
||||||
self.client.upgrade().unwrap()
|
self.client.upgrade()
|
||||||
}
|
}
|
||||||
// pub fn get_name(&self) -> &str {
|
// pub fn get_name(&self) -> &str {
|
||||||
// &self.path[self.trailing_slash_pos + 1..]
|
// &self.path[self.trailing_slash_pos + 1..]
|
||||||
@@ -123,10 +123,12 @@ impl Node {
|
|||||||
node
|
node
|
||||||
}
|
}
|
||||||
pub fn add_to_scenegraph(self) -> Arc<Node> {
|
pub fn add_to_scenegraph(self) -> Arc<Node> {
|
||||||
self.get_client().scenegraph.add_node(self)
|
self.get_client().unwrap().scenegraph.add_node(self)
|
||||||
}
|
}
|
||||||
pub fn destroy(&self) {
|
pub fn destroy(&self) {
|
||||||
let _ = self.get_client().scenegraph.remove_node(self.get_path());
|
let _ = self
|
||||||
|
.get_client()
|
||||||
|
.map(|c| c.scenegraph.remove_node(self.get_path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
pub fn destroy_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
||||||
@@ -203,24 +205,28 @@ impl Node {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.send_remote_signal(method, data);
|
.send_remote_signal(method, data);
|
||||||
});
|
});
|
||||||
let client = self.get_client();
|
|
||||||
let path = self.path.clone();
|
let path = self.path.clone();
|
||||||
let method = method.to_string();
|
let method = method.to_string();
|
||||||
let data = data.to_vec();
|
let data = data.to_vec();
|
||||||
|
if let Some(client) = self.get_client() {
|
||||||
if let Some(messenger) = client.messenger.as_ref() {
|
if let Some(messenger) = client.messenger.as_ref() {
|
||||||
messenger.send_remote_signal(path.as_str(), method.as_str(), data.as_slice());
|
messenger.send_remote_signal(path.as_str(), method.as_str(), data.as_slice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub async fn execute_remote_method(&self, method: &str, data: Vec<u8>) -> Result<Vec<u8>> {
|
pub async fn execute_remote_method(&self, method: &str, data: Vec<u8>) -> Result<Vec<u8>> {
|
||||||
match self.get_client().messenger.as_ref() {
|
if let Some(client) = self.get_client() {
|
||||||
None => Err(anyhow!("Messenger does not exist for this node's client")),
|
match client.messenger.as_ref() {
|
||||||
Some(messenger) => {
|
None => Err(anyhow!("Messenger does not exist for this node's client")),
|
||||||
messenger
|
Some(messenger) => {
|
||||||
.execute_remote_method(self.path.as_str(), method, &data)
|
messenger
|
||||||
.await
|
.execute_remote_method(self.path.as_str(), method, &data)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Client does not exist somehow?"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user