Browse Source

Fixed deserialization of key frames

flabbet 1 year ago
parent
commit
e01361f67e

+ 2 - 2
src/PixiEditor.AvaloniaUI/Helpers/Converters/DurationToWidthConverter.cs

@@ -14,7 +14,7 @@ internal class DurationToWidthConverter : SingleInstanceMultiValueConverter<Dura
     {
         if (values.Count != 2)
         {
-            return 0;
+            return 0.0;
             throw new ArgumentException("DurationToWidthConverter requires 2 values");
         }
         
@@ -23,6 +23,6 @@ internal class DurationToWidthConverter : SingleInstanceMultiValueConverter<Dura
             return scale * duration;
         }
         
-        return 0;
+        return 0.0;
     }
 }

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Animations/RasterKeyFrame.cs

@@ -23,7 +23,7 @@ internal class RasterKeyFrame : KeyFrame, IReadOnlyRasterKeyFrame
     public override KeyFrame Clone()
     {
         var image = targetImage.CloneFromCommitted();
-        return new RasterKeyFrame(Id, targetNode, StartFrame, Document, image);
+        return new RasterKeyFrame(Id, targetNode, StartFrame, Document, image) { Duration = Duration, IsVisible = IsVisible };
     }
 
     public IReadOnlyChunkyImage Image => targetImage;

+ 4 - 1
src/PixiEditor.ChangeableDocument/Changes/Animation/CreateRasterKeyFrame_Change.cs

@@ -58,8 +58,11 @@ internal class CreateRasterKeyFrame_Change : Change
         {
             _frame = existingData.StartFrame;
             duration = existingData.Duration;
-
             isVisible = existingData.IsVisible;
+            
+            keyFrame.StartFrame = _frame;
+            keyFrame.Duration = duration;
+            keyFrame.IsVisible = isVisible;
         }
 
         target.AnimationData.AddKeyFrame(keyFrame);

+ 8 - 1
src/PixiEditor.ChangeableDocument/Changes/Animation/DeleteKeyFrame_Change.cs

@@ -36,6 +36,13 @@ internal class DeleteKeyFrame_Change : Change
     public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
     {
         target.AnimationData.AddKeyFrame(clonedKeyFrame.Clone());
-        return new CreateRasterKeyFrame_ChangeInfo(clonedKeyFrame.NodeId, clonedKeyFrame.StartFrame, clonedKeyFrame.Id, false);   
+        List<IChangeInfo> changes = new List<IChangeInfo>
+        {
+           new CreateRasterKeyFrame_ChangeInfo(clonedKeyFrame.NodeId, clonedKeyFrame.StartFrame, clonedKeyFrame.Id, false),
+           new KeyFrameVisibility_ChangeInfo(clonedKeyFrame.Id, clonedKeyFrame.IsVisible),
+           new KeyFrameLength_ChangeInfo(clonedKeyFrame.Id, clonedKeyFrame.StartFrame, clonedKeyFrame.Duration)
+        };
+        
+        return changes;
     }
 }