Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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<FrontendNodeType>,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,29 @@ impl DefinitionIdentifier {
}),
}
}

pub fn serialized(&self) -> String {
match self {
DefinitionIdentifier::ProtoNode(id) => {
format!("Proto Node:{}", id.as_str())
}
DefinitionIdentifier::Network(data) => {
format!("Network:{}", data)
}
}
}
}

impl From<Value> 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),
}
}
let (ty, data) = s.split_once(':').expect("Invalid DefinitionIdentifier key format");

_ => panic!("Expected a JSON object to convert to `DefinitionIdentifier`"),
match ty {
"Proto Node" => DefinitionIdentifier::ProtoNode(ProtoNodeIdentifier::with_owned_string(data.to_string())),
"Network" => DefinitionIdentifier::Network(data.to_string()),
other => panic!("Unknown DefinitionIdentifier type: {other}"),
}
}
}
Expand Down Expand Up @@ -2682,7 +2682,7 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
name = identifier.implementation_name_from_identifier()
}
FrontendNodeType {
identifier: identifier.clone(),
identifier: identifier.serialized(),
name,
category: definition.category.to_string(),
input_types,
Expand All @@ -2691,10 +2691,15 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
.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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -79,7 +78,7 @@ pub struct FrontendNode {
pub is_layer: bool,
#[serde(rename = "canBeLayer")]
pub can_be_layer: bool,
pub reference: Option<DefinitionIdentifier>,
pub reference: Option<String>,
#[serde(rename = "displayName")]
pub display_name: String,
#[serde(rename = "implementationName")]
Expand All @@ -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")]
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/floating-menus/NodeCatalog.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script lang="ts">
import { createEventDispatcher, getContext, onMount } from "svelte";

import type { DefinitionIdentifier, FrontendNodeType } from "@graphite/messages";
import type { FrontendNodeType } from "@graphite/messages";
import type { NodeGraphState } from "@graphite/state-providers/node-graph";

import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";
import TextButton from "@graphite/components/widgets/buttons/TextButton.svelte";
import TextInput from "@graphite/components/widgets/inputs/TextInput.svelte";
import TextLabel from "@graphite/components/widgets/labels/TextLabel.svelte";

const dispatch = createEventDispatcher<{ selectNodeType: DefinitionIdentifier }>();
const dispatch = createEventDispatcher<{ selectNodeType: string }>();
const nodeGraph = getContext<NodeGraphState>("nodeGraph");

// Content
Expand Down Expand Up @@ -125,7 +125,7 @@
{disabled}
label={nodeType.name}
tooltipLabel={nodeType.name}
tooltipDescription={$nodeGraph.nodeDescriptions.get(nodeType.identifier)}
tooltipDescription={nodeType.identifier ? $nodeGraph.nodeDescriptions.get(nodeType.identifier) : undefined}
action={() => dispatch("selectNodeType", nodeType.identifier)}
/>
{/each}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/views/Graph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { fade } from "svelte/transition";

import type { Editor } from "@graphite/editor";
import type { DefinitionIdentifier, FrontendGraphInput, FrontendGraphOutput, FrontendNode } from "@graphite/messages";
import type { FrontendGraphInput, FrontendGraphOutput, FrontendNode } from "@graphite/messages";
import type { NodeGraphState } from "@graphite/state-providers/node-graph";

import NodeCatalog from "@graphite/components/floating-menus/NodeCatalog.svelte";
Expand Down Expand Up @@ -100,7 +100,7 @@
return sparse;
}

function createNode(identifier: DefinitionIdentifier) {
function createNode(identifier: string) {
if ($nodeGraph.contextMenuInformation === undefined) return;

editor.handle.createNode(identifier, $nodeGraph.contextMenuInformation.contextMenuCoordinates.x, $nodeGraph.contextMenuInformation.contextMenuCoordinates.y);
Expand Down Expand Up @@ -481,7 +481,7 @@
{@const layerAreaWidth = $nodeGraph.layerWidths.get(node.id) || 8}
{@const layerChainWidth = $nodeGraph.chainWidths.get(node.id) || 0}
{@const hasLeftInputWire = $nodeGraph.hasLeftInputWire.get(node.id) || false}
{@const description = (node.reference && $nodeGraph.nodeDescriptions.get(node.reference)) || undefined}
{@const description = node.reference ? $nodeGraph.nodeDescriptions.get(node.reference) : undefined}
<div
class="layer"
class:selected={$nodeGraph.selected.includes(node.id)}
Expand Down Expand Up @@ -634,7 +634,7 @@
.map(([_, node], nodeIndex) => ({ node, nodeIndex })) as { node, nodeIndex } (nodeIndex)}
{@const exposedInputsOutputs = zipWithUndefined(node.exposedInputs, node.exposedOutputs)}
{@const clipPathId = String(Math.random()).substring(2)}
{@const description = (node.reference && $nodeGraph.nodeDescriptions.get(node.reference)) || undefined}
{@const description = node.reference ? $nodeGraph.nodeDescriptions.get(node.reference) : undefined}
<div
class="node"
class:selected={$nodeGraph.selected.includes(node.id)}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class UpdateNodeGraphTransform extends JsMessage {

export class SendUIMetadata extends JsMessage {
@Transform(({ obj }) => new Map(obj.nodeDescriptions))
readonly nodeDescriptions!: Map<DefinitionIdentifier, string>;
readonly nodeDescriptions!: Map<string, string>;

readonly nodeTypes!: FrontendNodeType[];
}
Expand Down Expand Up @@ -220,7 +220,7 @@ export class FrontendNode {

readonly canBeLayer!: boolean;

readonly reference!: DefinitionIdentifier | undefined;
readonly reference!: string | undefined;

readonly displayName!: string;

Expand Down Expand Up @@ -251,7 +251,7 @@ export class FrontendNode {
}

export class FrontendNodeType {
readonly identifier!: DefinitionIdentifier;
readonly identifier!: string;

readonly name!: string;

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/state-providers/node-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
type FrontendNode,
type FrontendNodeType,
type WirePath,
type DefinitionIdentifier,

Check failure on line 12 in frontend/src/state-providers/node-graph.ts

View workflow job for this annotation

GitHub Actions / build

'DefinitionIdentifier' is defined but never used. Allowed unused vars must match /^_/u
ClearAllNodeGraphWires,
SendUIMetadata,
UpdateBox,
Expand Down Expand Up @@ -45,7 +45,7 @@
/// The index is the exposed input index. The exports have a first key value of u32::MAX.
wires: new Map<bigint, Map<number, WirePath>>(),
wirePathInProgress: undefined as WirePath | undefined,
nodeDescriptions: new Map<DefinitionIdentifier, string>(),
nodeDescriptions: new Map<string, string>(),
nodeTypes: [] as FrontendNodeType[],
thumbnails: new Map<bigint, string>(),
selected: [] as bigint[],
Expand Down
Loading