Browse Source

Don't throw on not clonable value, return default instead

flabbet 11 months ago
parent
commit
59897021ff

+ 8 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/InputProperty.cs

@@ -142,7 +142,7 @@ public class InputProperty : IInputProperty
             return new InputProperty(forNode, InternalPropertyName, DisplayName, enumVal, ValueType);
             return new InputProperty(forNode, InternalPropertyName, DisplayName, enumVal, ValueType);
         }
         }
 
 
-        if (NonOverridenValue is null)
+        if (NonOverridenValue is null || (!NonOverridenValue.GetType().IsValueType && NonOverridenValue.GetType() != typeof(string)))
         {
         {
             object? nullValue = null;
             object? nullValue = null;
             if (ValueType.IsValueType)
             if (ValueType.IsValueType)
@@ -153,8 +153,13 @@ public class InputProperty : IInputProperty
             return new InputProperty(forNode, InternalPropertyName, DisplayName, nullValue, ValueType);
             return new InputProperty(forNode, InternalPropertyName, DisplayName, nullValue, ValueType);
         }
         }
         
         
-        if(!NonOverridenValue.GetType().IsValueType && NonOverridenValue.GetType() != typeof(string))
-            throw new InvalidOperationException("Value is not cloneable and not a primitive type");
+        /*if(!NonOverridenValue.GetType().IsValueType && NonOverridenValue.GetType() != typeof(string))
+            throw new InvalidOperationException($"Value of type {NonOverridenValue.GetType()} is not cloneable and not a primitive type");*/
+
+        if (!NonOverridenValue.GetType().IsValueType && NonOverridenValue.GetType() != typeof(string))
+        {
+            
+        }
         
         
         return new InputProperty(forNode, InternalPropertyName, DisplayName, NonOverridenValue, ValueType);
         return new InputProperty(forNode, InternalPropertyName, DisplayName, NonOverridenValue, ValueType);
     }
     }

+ 15 - 13
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Node.cs

@@ -5,6 +5,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.Common;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Shaders;
 using PixiEditor.DrawingApi.Core.Shaders;
@@ -66,13 +67,13 @@ public abstract class Node : IReadOnlyNode, IDisposable
     private bool _keyFramesDirty;
     private bool _keyFramesDirty;
     private Texture? _lastCachedResult;
     private Texture? _lastCachedResult;
     private bool _isDisposed;
     private bool _isDisposed;
-    
+
     private Dictionary<int, Texture> _managedTextures = new();
     private Dictionary<int, Texture> _managedTextures = new();
 
 
     public Texture? Execute(RenderingContext context)
     public Texture? Execute(RenderingContext context)
     {
     {
         var result = ExecuteInternal(context);
         var result = ExecuteInternal(context);
-        
+
         if (result is null)
         if (result is null)
         {
         {
             return null;
             return null;
@@ -84,8 +85,8 @@ public abstract class Node : IReadOnlyNode, IDisposable
 
 
     internal Texture? ExecuteInternal(RenderingContext context)
     internal Texture? ExecuteInternal(RenderingContext context)
     {
     {
-        if(_isDisposed) throw new ObjectDisposedException("Node was disposed before execution.");
-        
+        if (_isDisposed) throw new ObjectDisposedException("Node was disposed before execution.");
+
         if (!CacheChanged(context)) return CachedResult;
         if (!CacheChanged(context)) return CachedResult;
 
 
         CachedResult = OnExecute(context);
         CachedResult = OnExecute(context);
@@ -93,7 +94,7 @@ public abstract class Node : IReadOnlyNode, IDisposable
         {
         {
             throw new ObjectDisposedException("Texture was disposed after execution.");
             throw new ObjectDisposedException("Texture was disposed after execution.");
         }
         }
-        
+
         UpdateCache(context);
         UpdateCache(context);
         return CachedResult;
         return CachedResult;
     }
     }
@@ -133,15 +134,15 @@ public abstract class Node : IReadOnlyNode, IDisposable
                 _managedTextures[id] = texture;
                 _managedTextures[id] = texture;
                 return texture;
                 return texture;
             }
             }
-            
+
             if (clear)
             if (clear)
             {
             {
                 texture.DrawingSurface.Canvas.Clear(Colors.Transparent);
                 texture.DrawingSurface.Canvas.Clear(Colors.Transparent);
             }
             }
-            
+
             return texture;
             return texture;
         }
         }
-        
+
         _managedTextures[id] = new Texture(size);
         _managedTextures[id] = new Texture(size);
         return _managedTextures[id];
         return _managedTextures[id];
     }
     }
@@ -315,7 +316,7 @@ public abstract class Node : IReadOnlyNode, IDisposable
                 keyFrame.Dispose();
                 keyFrame.Dispose();
             }
             }
         }
         }
-        
+
         foreach (var texture in _managedTextures)
         foreach (var texture in _managedTextures)
         {
         {
             texture.Value.Dispose();
             texture.Value.Dispose();
@@ -370,18 +371,19 @@ public abstract class Node : IReadOnlyNode, IDisposable
         {
         {
             var cloneOutput = outputs[i];
             var cloneOutput = outputs[i];
             var newOutput = cloneOutput.Clone(clone);
             var newOutput = cloneOutput.Clone(clone);
-            clone.outputs[i].Value = newOutput.Value; 
+            clone.outputs[i].Value = newOutput.Value;
         }
         }
-        
+
         foreach (var keyFrame in keyFrames)
         foreach (var keyFrame in keyFrames)
         {
         {
             KeyFrameData newKeyFrame = new KeyFrameData(keyFrame.KeyFrameGuid, keyFrame.StartFrame, keyFrame.Duration,
             KeyFrameData newKeyFrame = new KeyFrameData(keyFrame.KeyFrameGuid, keyFrame.StartFrame, keyFrame.Duration,
                 keyFrame.AffectedElement)
                 keyFrame.AffectedElement)
             {
             {
-                IsVisible = keyFrame.IsVisible, Duration = keyFrame.Duration,
+                IsVisible = keyFrame.IsVisible,
+                Duration = keyFrame.Duration,
                 Data = keyFrame.Data is ICloneable cloneable ? cloneable.Clone() : keyFrame.Data
                 Data = keyFrame.Data is ICloneable cloneable ? cloneable.Clone() : keyFrame.Data
             };
             };
-            
+
             clone.keyFrames.Add(newKeyFrame);
             clone.keyFrames.Add(newKeyFrame);
         }
         }
 
 

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/OutputProperty.cs

@@ -68,7 +68,7 @@ public class OutputProperty : IOutputProperty
 
 
     public OutputProperty Clone(Node clone)
     public OutputProperty Clone(Node clone)
     {
     {
-        if (Value is null)
+        if (Value is null || (Value is not ICloneable && !Value.GetType().IsPrimitive && Value.GetType() != typeof(string)))
         {
         {
             object defaultValue = null;
             object defaultValue = null;
             if(ValueType.IsValueType)
             if(ValueType.IsValueType)

+ 6 - 1
src/PixiEditor.DrawingApi.Core/Texture.cs

@@ -9,7 +9,7 @@ using PixiEditor.Numerics;
 
 
 namespace PixiEditor.DrawingApi.Core;
 namespace PixiEditor.DrawingApi.Core;
 
 
-public class Texture : IDisposable
+public class Texture : IDisposable, ICloneable
 {
 {
     public VecI Size { get; }
     public VecI Size { get; }
     public DrawingSurface DrawingSurface { get; private set; }
     public DrawingSurface DrawingSurface { get; private set; }
@@ -54,6 +54,11 @@ public class Texture : IDisposable
         DrawingSurface.Changed -= DrawingSurfaceOnChanged;
         DrawingSurface.Changed -= DrawingSurfaceOnChanged;
     }
     }
 
 
+    public object Clone()
+    {
+        return new Texture(this);
+    }
+
     private void DrawingSurfaceOnChanged(RectD? changedRect)
     private void DrawingSurfaceOnChanged(RectD? changedRect)
     {
     {
         Changed?.Invoke(changedRect);
         Changed?.Invoke(changedRect);