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