mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 13:30:48 +00:00
* WIP, for TrueDoctor to continue * Expose first implementation type as default type in field metadata * Cleanup --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
e41471c088
commit
fd81d043a2
4 changed files with 30 additions and 10 deletions
|
@ -2697,7 +2697,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
|||
.iter()
|
||||
.zip(first_node_io.inputs.iter())
|
||||
.enumerate()
|
||||
.map(|(index, (field, ty))| {
|
||||
.map(|(index, (field, node_io_ty))| {
|
||||
let ty = field.default_type.as_ref().unwrap_or(node_io_ty);
|
||||
let exposed = if index == 0 { *ty != fn_type!(()) } else { field.exposed };
|
||||
|
||||
match field.value_source {
|
||||
|
|
|
@ -6,6 +6,7 @@ use crate::messages::layout::utility_types::widget_prelude::*;
|
|||
use crate::messages::portfolio::document::utility_types::network_interface::InputConnector;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use dyn_any::DynAny;
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
|
||||
use graph_craft::imaginate_input::{ImaginateMaskStartingFill, ImaginateSamplingMethod};
|
||||
|
@ -2128,7 +2129,7 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
|
|||
|
||||
let mut number_options = (None, None, None);
|
||||
let input_type = match implementation {
|
||||
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
|
||||
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => 'early_return: {
|
||||
if let Some(field) = graphene_core::registry::NODE_METADATA
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
@ -2136,16 +2137,22 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
|
|||
.and_then(|metadata| metadata.fields.get(input_index))
|
||||
{
|
||||
number_options = (field.number_min, field.number_max, field.number_mode_range);
|
||||
if let Some(ref default) = field.default_type {
|
||||
break 'early_return default.clone();
|
||||
}
|
||||
}
|
||||
let Some(implementations) = &interpreted_executor::node_registry::NODE_REGISTRY.get(proto_node_identifier) else {
|
||||
log::error!("Could not get implementation for protonode {proto_node_identifier:?}");
|
||||
return Vec::new();
|
||||
};
|
||||
let proto_node_identifier = proto_node_identifier.clone();
|
||||
let input_type = implementations
|
||||
let mut input_types = implementations
|
||||
.keys()
|
||||
.filter_map(|item| item.inputs.get(input_index))
|
||||
.find(|item| property_from_type(node_id, input_index, item, number_options, context).is_ok());
|
||||
.filter(|ty| property_from_type(node_id, input_index, ty, number_options, context).is_ok())
|
||||
.collect::<Vec<_>>();
|
||||
input_types.sort_by_key(|ty| ty.type_name());
|
||||
let input_type = input_types.first().cloned();
|
||||
let Some(input_type) = input_type else {
|
||||
log::error!("Could not get input type for protonode {proto_node_identifier:?} at index {input_index:?}");
|
||||
return Vec::new();
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use crate::transform::Footprint;
|
||||
use crate::{NodeIO, NodeIOTypes, Type};
|
||||
|
||||
use dyn_any::DynAny;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Deref;
|
||||
use std::pin::Pin;
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
|
||||
use dyn_any::DynAny;
|
||||
|
||||
use crate::transform::Footprint;
|
||||
use crate::NodeIO;
|
||||
use crate::NodeIOTypes;
|
||||
|
||||
pub mod types {
|
||||
/// 0% - 100%
|
||||
pub type Percentage = f64;
|
||||
|
@ -47,6 +46,7 @@ pub struct FieldMetadata {
|
|||
pub exposed: bool,
|
||||
pub widget_override: RegistryWidgetOverride,
|
||||
pub value_source: RegistryValueSource,
|
||||
pub default_type: Option<Type>,
|
||||
pub number_min: Option<f64>,
|
||||
pub number_max: Option<f64>,
|
||||
pub number_mode_range: Option<(f64, f64)>,
|
||||
|
|
|
@ -117,6 +117,17 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
|
|||
})
|
||||
.collect();
|
||||
|
||||
let default_types: Vec<_> = fields
|
||||
.iter()
|
||||
.map(|field| match field {
|
||||
ParsedField::Regular { implementations, .. } => match implementations.first() {
|
||||
Some(ty) => quote!(Some(concrete!(#ty))),
|
||||
_ => quote!(None),
|
||||
},
|
||||
_ => quote!(None),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let number_min_values: Vec<_> = fields
|
||||
.iter()
|
||||
.map(|field| match field {
|
||||
|
@ -292,6 +303,7 @@ pub(crate) fn generate_node_code(parsed: &ParsedNodeFn) -> syn::Result<TokenStre
|
|||
description: #input_descriptions,
|
||||
exposed: #exposed,
|
||||
value_source: #value_sources,
|
||||
default_type: #default_types,
|
||||
number_min: #number_min_values,
|
||||
number_max: #number_max_values,
|
||||
number_mode_range: #number_mode_range_values,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue