Browse Source

Fixed default values node properties not being given to front end

CPKreuz 1 year ago
parent
commit
74c34f7898

+ 1 - 0
src/PixiEditor.AvaloniaUI/Models/DocumentModels/DocumentUpdater.cs

@@ -517,6 +517,7 @@ internal class DocumentUpdater
             prop.PropertyName = input.PropertyName;
             prop.IsInput = isInput;
             prop.IsFunc = input.ValueType.IsAssignableTo(typeof(Delegate));
+            prop.InternalSetValue(input.InputValue);
             inputs.Add(prop);
         }
         

+ 9 - 1
src/PixiEditor.ChangeableDocument/ChangeInfos/NodeGraph/CreateNode_ChangeInfo.cs

@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Collections.Immutable;
+using PixiEditor.ChangeableDocument.Changeables.Graph;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.Numerics;
 
@@ -16,7 +17,7 @@ public record CreateNode_ChangeInfo(
     public static ImmutableArray<NodePropertyInfo> CreatePropertyInfos(IEnumerable<INodeProperty> properties,
         bool isInput, Guid guid)
     {
-        return properties.Select(p => new NodePropertyInfo(p.InternalPropertyName, p.DisplayName, p.ValueType, isInput, guid))
+        return properties.Select(p => new NodePropertyInfo(p.InternalPropertyName, p.DisplayName, p.ValueType, isInput, GetNonOverridenValue(p), guid))
             .ToImmutableArray();
     }
 
@@ -29,4 +30,11 @@ public record CreateNode_ChangeInfo(
             node.Id,
             CreatePropertyInfos(node.InputProperties, true, node.Id), CreatePropertyInfos(node.OutputProperties, false, node.Id));
     }
+
+    private static object? GetNonOverridenValue(INodeProperty property) => property switch
+    {
+        IFieldInputProperty fieldProperty => fieldProperty.GetFieldConstantValue(),
+        IInputProperty inputProperty => inputProperty.NonOverridenValue,
+        _ => null
+    };
 }

+ 4 - 1
src/PixiEditor.ChangeableDocument/ChangeInfos/NodeGraph/NodePropertyInfo.cs

@@ -1,8 +1,11 @@
-namespace PixiEditor.ChangeableDocument.ChangeInfos.NodeGraph;
+using System.Diagnostics.CodeAnalysis;
+
+namespace PixiEditor.ChangeableDocument.ChangeInfos.NodeGraph;
 
 public record NodePropertyInfo(
     string PropertyName,
     string DisplayName,
     Type ValueType,
     bool IsInput,
+    object? InputValue,
     Guid NodeId);