diff --git a/editor/src/messages/frontend/frontend_message.rs b/editor/src/messages/frontend/frontend_message.rs index 0f47b6f5f7..e6c724069f 100644 --- a/editor/src/messages/frontend/frontend_message.rs +++ b/editor/src/messages/frontend/frontend_message.rs @@ -2,7 +2,6 @@ use super::utility_types::{DocumentDetails, MouseCursorIcon, OpenDocument}; use crate::messages::app_window::app_window_message_handler::AppWindowPlatform; use crate::messages::input_mapper::utility_types::misc::ActionShortcut; use crate::messages::layout::utility_types::widget_prelude::*; -use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier; use crate::messages::portfolio::document::node_graph::utility_types::{ BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic, Transform, }; @@ -61,7 +60,7 @@ pub enum FrontendMessage { // Send prefix: Send global, static data to the frontend that is never updated SendUIMetadata { #[serde(rename = "nodeDescriptions")] - node_descriptions: Vec<(DefinitionIdentifier, String)>, + node_descriptions: Vec<(String, String)>, #[serde(rename = "nodeTypes")] node_types: Vec, }, diff --git a/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs b/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs index bb90f2c946..998207914c 100644 --- a/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs +++ b/editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs @@ -80,29 +80,23 @@ impl DefinitionIdentifier { }), } } + + pub fn serialized(&self) -> String { + match self { + DefinitionIdentifier::ProtoNode(id) => format!("PROTONODE:{}", id.as_str()), + DefinitionIdentifier::Network(data) => format!("NETWORK:{}", data), + } + } } impl From for DefinitionIdentifier { fn from(value: Value) -> Self { - match value { - Value::Object(mut map) => { - let ty = map.remove("type").unwrap().as_str().unwrap().to_owned(); + let s = value.as_str().expect("DefinitionIdentifier value must be a string"); - match ty.as_ref() { - "Network" => { - let data = map.remove("data").unwrap().as_str().unwrap().to_owned(); - DefinitionIdentifier::Network(data) - } - "ProtoNode" => { - let value = map.remove("data").unwrap(); - let proto: ProtoNodeIdentifier = serde_json::from_value(value).unwrap(); - DefinitionIdentifier::ProtoNode(proto) - } - _ => panic!("Unknown `DefinitionIdentifier` type: {:?}", ty), - } - } - - _ => panic!("Expected a JSON object to convert to `DefinitionIdentifier`"), + match s.split_once(':') { + Some(("PROTONODE", data)) => DefinitionIdentifier::ProtoNode(ProtoNodeIdentifier::with_owned_string(data.to_string())), + Some(("NETWORK", data)) => DefinitionIdentifier::Network(data.to_string()), + other => panic!("Unknown `DefinitionIdentifier` type. Found `{other:?}`."), } } } @@ -2621,7 +2615,7 @@ pub fn collect_node_types() -> Vec { name = identifier.implementation_name_from_identifier() } FrontendNodeType { - identifier: identifier.clone(), + identifier: identifier.serialized(), name, category: definition.category.to_string(), input_types, @@ -2630,10 +2624,15 @@ pub fn collect_node_types() -> Vec { .collect() } -pub fn collect_node_descriptions() -> Vec<(DefinitionIdentifier, String)> { +pub fn collect_node_descriptions() -> Vec<(String, String)> { DOCUMENT_NODE_TYPES .iter() - .map(|(identifier, definition)| (identifier.clone(), if definition.description != "TODO" { definition.description.to_string() } else { String::new() })) + .map(|(identifier, definition)| { + ( + identifier.serialized(), + if definition.description != "TODO" { definition.description.to_string() } else { String::new() }, + ) + }) .collect() } diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs index a171ef360d..c26b21af5c 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs @@ -2599,7 +2599,7 @@ impl NodeGraphMessageHandler { .node_metadata(&node_id, breadcrumb_network_path) .is_some_and(|node_metadata| node_metadata.persistent_metadata.is_layer()), can_be_layer: network_interface.is_eligible_to_be_layer(&node_id, breadcrumb_network_path), - reference: network_interface.reference(&node_id, breadcrumb_network_path), + reference: network_interface.reference(&node_id, breadcrumb_network_path).map(|reference| reference.serialized()), display_name: network_interface.display_name(&node_id, breadcrumb_network_path), implementation_name: network_interface.implementation_name(&node_id, breadcrumb_network_path), primary_input, @@ -2715,16 +2715,12 @@ impl NodeGraphMessageHandler { } }); - let Some(reference) = network_interface.reference(&node_id, &[]) else { - log::error!("Could not get reference for layer {node_id} in update_layer_panel"); - continue; - }; - let clippable = layer.can_be_clipped(network_interface.document_metadata()); let data = LayerPanelEntry { id: node_id, - reference, + implementation_name: network_interface.implementation_name(&node_id, &[]), + icon_name: network_interface.is_artboard(&node_id, &[]).then(|| "Artboard".to_string()), alias: network_interface.display_name(&node_id, &[]), in_selected_network: selection_network_path.is_empty(), children_allowed, diff --git a/editor/src/messages/portfolio/document/node_graph/utility_types.rs b/editor/src/messages/portfolio/document/node_graph/utility_types.rs index 54ca255e84..12d6780fc1 100644 --- a/editor/src/messages/portfolio/document/node_graph/utility_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/utility_types.rs @@ -1,4 +1,3 @@ -use super::document_node_definitions::DefinitionIdentifier; use glam::{DVec2, IVec2}; use graph_craft::document::NodeId; use graph_craft::document::value::TaggedValue; @@ -79,7 +78,7 @@ pub struct FrontendNode { pub is_layer: bool, #[serde(rename = "canBeLayer")] pub can_be_layer: bool, - pub reference: Option, + pub reference: Option, #[serde(rename = "displayName")] pub display_name: String, #[serde(rename = "implementationName")] @@ -104,7 +103,7 @@ pub struct FrontendNode { #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)] pub struct FrontendNodeType { - pub identifier: DefinitionIdentifier, + pub identifier: String, pub name: String, pub category: String, #[serde(rename = "inputTypes")] diff --git a/editor/src/messages/portfolio/document/utility_types/nodes.rs b/editor/src/messages/portfolio/document/utility_types/nodes.rs index 789b64b0bf..07f262b382 100644 --- a/editor/src/messages/portfolio/document/utility_types/nodes.rs +++ b/editor/src/messages/portfolio/document/utility_types/nodes.rs @@ -1,6 +1,5 @@ use super::document_metadata::{DocumentMetadata, LayerNodeIdentifier}; use super::network_interface::NodeNetworkInterface; -use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier; use crate::messages::tool::common_functionality::graph_modification_utils; use glam::DVec2; use graph_craft::document::{NodeId, NodeNetwork}; @@ -35,7 +34,10 @@ impl serde::Serialize for JsRawBuffer { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, specta::Type)] pub struct LayerPanelEntry { pub id: NodeId, - pub reference: DefinitionIdentifier, + #[serde(rename = "implementationName")] + pub implementation_name: String, + #[serde(rename = "iconName")] + pub icon_name: Option, pub alias: String, #[serde(rename = "inSelectedNetwork")] pub in_selected_network: bool, diff --git a/frontend/src/components/floating-menus/NodeCatalog.svelte b/frontend/src/components/floating-menus/NodeCatalog.svelte index dac04949dd..13af50a772 100644 --- a/frontend/src/components/floating-menus/NodeCatalog.svelte +++ b/frontend/src/components/floating-menus/NodeCatalog.svelte @@ -1,7 +1,7 @@