Browse Source

Fixed input property duplicating wrong

Krzysztof Krysiński 5 months ago
parent
commit
d6b642d685

+ 6 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/FuncInputProperty.cs

@@ -20,6 +20,11 @@ public class FuncInputProperty<T> : InputProperty<Func<FuncContext, T>>, IFuncIn
         NonOverridenValue = _ => constantNonOverrideValue;
         NonOverridenValue = _ => constantNonOverrideValue;
     }
     }
 
 
+    protected override void NonOverridenValueSet(Func<FuncContext, T> value)
+    {
+        constantNonOverrideValue = value(FuncContext.NoContext);
+    }
+
     protected internal override object FuncFactory(object toReturn)
     protected internal override object FuncFactory(object toReturn)
     {
     {
         Func<FuncContext, T> func = _ =>
         Func<FuncContext, T> func = _ =>
@@ -133,6 +138,7 @@ public class FuncInputProperty<T> : InputProperty<Func<FuncContext, T>>, IFuncIn
         if (constantNonOverrideValue is ShaderExpressionVariable shaderExpressionVariable)
         if (constantNonOverrideValue is ShaderExpressionVariable shaderExpressionVariable)
         {
         {
             shaderExpressionVariable.SetConstantValue(value, ConversionTable.Convert);
             shaderExpressionVariable.SetConstantValue(value, ConversionTable.Convert);
+            NonOverridenValue = _ => constantNonOverrideValue;
             return;
             return;
         }
         }
 
 

+ 21 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/InputProperty.cs

@@ -51,6 +51,7 @@ public class InputProperty : IInputProperty
         set
         set
         {
         {
             _internalValue = value;
             _internalValue = value;
+            NonOverridenValueSet(value);
         }
         }
     }
     }
 
 
@@ -121,6 +122,10 @@ public class InputProperty : IInputProperty
         }
         }
     }
     }
 
 
+    protected virtual void NonOverridenValueSet(object value)
+    {
+    }
+
     internal virtual void UpdateCache()
     internal virtual void UpdateCache()
     {
     {
         if (Value is null)
         if (Value is null)
@@ -199,7 +204,22 @@ public class InputProperty<T> : InputProperty, IInputProperty<T>
     public T NonOverridenValue
     public T NonOverridenValue
     {
     {
         get => (T)(base.NonOverridenValue ?? default(T));
         get => (T)(base.NonOverridenValue ?? default(T));
-        set => base.NonOverridenValue = value;
+        set
+        {
+            base.NonOverridenValue = value;
+        }
+    }
+
+    protected override void NonOverridenValueSet(object value)
+    {
+        if (value is T casted)
+        {
+            NonOverridenValueSet(casted);
+        }
+    }
+
+    protected virtual void NonOverridenValueSet(T value)
+    {
     }
     }
 
 
     internal InputProperty(Node node, string internalName, string displayName, T defaultValue) : base(node,
     internal InputProperty(Node node, string internalName, string displayName, T defaultValue) : base(node,

+ 2 - 1
src/PixiEditor/Models/DocumentModels/DocumentUpdater.cs

@@ -14,6 +14,7 @@ using PixiEditor.ChangeableDocument.ChangeInfos.Root.ReferenceLayerChangeInfos;
 using PixiEditor.ChangeableDocument.ChangeInfos.Structure;
 using PixiEditor.ChangeableDocument.ChangeInfos.Structure;
 using PixiEditor.ChangeableDocument.Enums;
 using PixiEditor.ChangeableDocument.Enums;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Shaders.Generation;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DocumentModels.Public;
 using PixiEditor.Models.DocumentModels.Public;
@@ -579,7 +580,7 @@ internal class DocumentUpdater
             prop.PropertyName = input.PropertyName;
             prop.PropertyName = input.PropertyName;
             prop.IsInput = isInput;
             prop.IsInput = isInput;
             prop.IsFunc = input.ValueType.IsAssignableTo(typeof(Delegate));
             prop.IsFunc = input.ValueType.IsAssignableTo(typeof(Delegate));
-            prop.InternalSetValue(input.InputValue);
+            prop.InternalSetValue(prop.IsFunc ? (input.InputValue as ShaderExpressionVariable)?.GetConstant() : input.InputValue);
             inputs.Add(prop);
             inputs.Add(prop);
         }
         }