Skip to content
Merged
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
8 changes: 4 additions & 4 deletions document/live/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use document_container::AnyContainer;
use document_container::backends::memory::MemoryBackend;
use document_format::{GddV1, GddV1Layout};
use document_graph_storage::{PeerId, UserId};
use document_graph_storage::{NodeMetadataEntry, PeerId, UserId};
use graph_craft::application_io::resource::ResourceHash;
use graph_craft::document::NodeNetwork;
use peer_transport::{Room, SyncTarget};
Expand Down Expand Up @@ -97,10 +97,10 @@ impl LiveDocument {
&mut self.gdd
}

pub async fn network(&self) -> Result<NodeNetwork, LiveError> {
/// The document's runtime network, with the metadata of each of its nodes.
pub async fn network_with_metadata(&self) -> Result<(NodeNetwork, Vec<NodeMetadataEntry>), LiveError> {
let declarations = self.gdd.declarations(&self.gdd).await;
let (network, _metadata) = self.gdd.registry().to_runtime_with_metadata(&declarations, self.gdd.blobs())?;
Ok(network)
Ok(self.gdd.registry().to_runtime_with_metadata(&declarations, self.gdd.blobs())?)
}

pub fn leave(&mut self) {
Expand Down
6 changes: 4 additions & 2 deletions editor/src/node_graph_executor/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use graphene_std::runtime::AsyncRuntime;
use graphene_std::vector::style::RenderMode;
use graphene_std::{Context, NodeError, Poll};
use interpreted_executor::dynamic_executor::{DynamicExecutor, ResolvedDocumentNodeTypesDelta};
use interpreted_executor::layer_paths::write_layer_paths;
use interpreted_executor::util::wrap_network_in_scope;
use observer::Observer;
pub use observer::{InspectResult, InspectedContext, Observation, ObservedConnector, ObservedValue};
Expand All @@ -27,7 +28,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Receiver, Sender};
use thumbnails::Thumbnails;

mod layer_content;
#[cfg(test)]
mod layer_path_tests;
mod observer;
mod thumbnails;

Expand Down Expand Up @@ -213,7 +215,7 @@ impl NodeRuntime {
};

apply_previews(&mut network, &previewed);
layer_content::write_layer_paths(&mut network, &layers);
write_layer_paths(&mut network, &layers);
self.observer.replace_all(observations);
self.resources = resources;

Expand Down
65 changes: 65 additions & 0 deletions editor/src/node_graph_executor/runtime/layer_path_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, OutputConnector};
use crate::test_utils::test_prelude::*;
use graphene_std::graphic::extend;

// A layer that ends in no Extend node has its path written onto its whole output, which gives the editor its click targets
#[tokio::test]
async fn a_node_shown_as_a_layer_is_traced_back_to() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
let rectangle = DefinitionIdentifier::ProtoNode(graphene_std::vector::generator_nodes::rectangle::IDENTIFIER);
let rectangle = editor.create_node_by_name_at(rectangle, 0, 0).await;
editor
.handle_message(NodeGraphMessage::CreateWire {
output_connector: OutputConnector::node(rectangle, 0),
input_connector: InputConnector::Export(0),
})
.await;
assert!(editor.active_document().metadata().click_targets.is_empty(), "A node not shown as a layer should have no click targets");

editor.handle_message(NodeGraphMessage::SetToNodeOrLayer { node_id: rectangle, is_layer: true }).await;

let document = editor.active_document();
let layer = LayerNodeIdentifier::new(rectangle, &document.network_interface);
let click_targets = document.metadata().click_targets(layer);
assert!(
click_targets.is_some_and(|click_targets| !click_targets.is_empty()),
"A node shown as a layer should have click targets"
);
}

// A layer that is itself an Extend node has its path written, from beside it, onto what it's given to add
#[tokio::test]
async fn an_extend_node_shown_as_a_layer_is_traced_back_to() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
let extend = editor.create_node_by_name_at(DefinitionIdentifier::ProtoNode(extend::IDENTIFIER), 0, 0).await;
let rectangle = DefinitionIdentifier::ProtoNode(graphene_std::vector::generator_nodes::rectangle::IDENTIFIER);
let (below, added) = (editor.create_node_by_name_at(rectangle.clone(), -10, 0).await, editor.create_node_by_name_at(rectangle, -10, 4).await);
for (rectangle, input) in [(below, InputConnector::node(extend, extend::BaseInput)), (added, InputConnector::node(extend, extend::NewInput))] {
editor
.handle_message(NodeGraphMessage::CreateWire {
output_connector: OutputConnector::node(rectangle, 0),
input_connector: input,
})
.await;
}
editor
.handle_message(NodeGraphMessage::CreateWire {
output_connector: OutputConnector::node(extend, 0),
input_connector: InputConnector::Export(0),
})
.await;

editor.handle_message(NodeGraphMessage::SetToNodeOrLayer { node_id: extend, is_layer: true }).await;

let document = editor.active_document();
let layer = LayerNodeIdentifier::new(extend, &document.network_interface);
let click_targets = document.metadata().click_targets(layer);
assert!(
click_targets.is_some_and(|click_targets| !click_targets.is_empty()),
"An Extend node shown as a layer should have click targets for what it adds"
);
}
4 changes: 2 additions & 2 deletions editor/src/node_graph_executor/runtime/thumbnails.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::evaluated_output;
use super::layer_content::layer_content;
use crate::messages::frontend::FrontendMessage;
#[cfg(feature = "gpu")]
use atlas::ThumbnailAtlasLayout;
Expand All @@ -21,6 +20,7 @@ use graphene_std::transform::{Footprint, RenderQuality};
use graphene_std::vector::Vector;
use graphene_std::{Artboard, Color, Context, ContextFeatures, Graphic};
use interpreted_executor::dynamic_executor::DynamicExecutor;
use interpreted_executor::layer_paths::layer_content;
use std::collections::{HashMap, HashSet, VecDeque};
use std::sync::Arc;

Expand Down Expand Up @@ -467,11 +467,11 @@ fn expand_to_thumbnail_aspect(bounds: [DVec2; 2]) -> [DVec2; 2] {
#[cfg(test)]
mod tests {
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, shipped_node_id};
use crate::node_graph_executor::runtime::layer_content::layer_path_writer_id;
use crate::test_utils::test_prelude::*;
use glam::UVec2;
use graph_craft::document::NodeId;
use graphene_std::application_io::TimingInformation;
use interpreted_executor::layer_paths::layer_path_writer_id;

async fn compile_and_run(editor: &mut EditorTestUtils) {
let portfolio = editor.portfolio_message_handler_mut();
Expand Down
4 changes: 4 additions & 0 deletions node-graph/graphene-cli/src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use graph_craft::ProtoNodeIdentifier;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeNetwork};
use graph_craft::proto::{ConstructionArgs, ProtoNetwork, ProtoNode};
use graphene_std::graphic::write_layer_path;
use graphene_std::simplify_identifier_name;
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use std::error::Error;
Expand Down Expand Up @@ -57,6 +58,7 @@ enum Kind {
Nullify,
Expand,
Scope,
LayerPath,
}

impl Kind {
Expand All @@ -68,6 +70,7 @@ impl Kind {
Kind::Nullify => "+nullify",
Kind::Expand => "+expand",
Kind::Scope => "+scope",
Kind::LayerPath => "+layer-path",
}
}
}
Expand Down Expand Up @@ -234,6 +237,7 @@ fn kind(proto: &ProtoNode, origin: &[NodeId], document: &Document) -> Kind {
_ if appended && path.last() == Some(&NodeId(10)) => Kind::Nullify,
_ if proto.original_location.auto_convert_index.is_some() => Kind::Convert,
ConstructionArgs::Value(_) => Kind::Value,
_ if proto.identifier == write_layer_path::IDENTIFIER => Kind::LayerPath,
_ if origin.is_empty() => Kind::Scope,
_ if document[origin].1.as_ref() == Some(&proto.identifier) => Kind::Document,
_ => Kind::Expand,
Expand Down
Loading
Loading