Browse Source

Added onion frames count serialization

flabbet 1 year ago
parent
commit
172d59a8c4

+ 3 - 0
src/PixiEditor.ChangeableDocument/ChangeInfos/Animation/OnionFrames_ChangeInfo.cs

@@ -0,0 +1,3 @@
+namespace PixiEditor.ChangeableDocument.ChangeInfos.Animation;
+
+public record OnionFrames_ChangeInfo(int OnionFrames) : IChangeInfo;

+ 1 - 0
src/PixiEditor.ChangeableDocument/Changeables/Animations/AnimationData.cs

@@ -6,6 +6,7 @@ namespace PixiEditor.ChangeableDocument.Changeables.Animations;
 internal class AnimationData : IReadOnlyAnimationData
 {
     public int FrameRate { get; set; } = 24;
+    public int OnionFrames { get; set; } = 1;
     public IReadOnlyList<IReadOnlyKeyFrame> KeyFrames => keyFrames;
 
     private List<KeyFrame> keyFrames = new List<KeyFrame>();

+ 1 - 0
src/PixiEditor.ChangeableDocument/Changeables/Interfaces/IReadOnlyAnimationData.cs

@@ -4,5 +4,6 @@ public interface IReadOnlyAnimationData
 {
     public int FrameRate { get; }
     public IReadOnlyList<IReadOnlyKeyFrame> KeyFrames { get; }
+    public int OnionFrames { get; }
     public bool TryFindKeyFrame<T>(Guid id, out T keyFrame) where T : IReadOnlyKeyFrame;
 }

+ 37 - 0
src/PixiEditor.ChangeableDocument/Changes/Animation/SetOnionFrames_Change.cs

@@ -0,0 +1,37 @@
+using PixiEditor.ChangeableDocument.ChangeInfos.Animation;
+
+namespace PixiEditor.ChangeableDocument.Changes.Animation;
+
+internal class SetOnionFrames_Change : Change
+{
+    public int OnionFrames { get; set; }
+    
+    private int oldOnionFrames;
+    
+    [GenerateMakeChangeAction]
+    public SetOnionFrames_Change(int onionFrames)
+    {
+        OnionFrames = onionFrames;
+    }
+    
+    public override bool InitializeAndValidate(Document target)
+    {
+        oldOnionFrames = target.AnimationData.OnionFrames;
+        return true;    
+    }
+
+    public override OneOf<None, IChangeInfo, List<IChangeInfo>> Apply(Document target, bool firstApply, out bool ignoreInUndo)
+    {
+        target.AnimationData.OnionFrames = OnionFrames;
+        
+        ignoreInUndo = true;
+        return new OnionFrames_ChangeInfo(OnionFrames);
+    }
+
+    public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
+    {
+        target.AnimationData.OnionFrames = oldOnionFrames;
+
+        return new OnionFrames_ChangeInfo(oldOnionFrames);
+    }
+}

+ 1 - 0
src/PixiEditor/Helpers/Behaviours/GlobalShortcutFocusBehavior.cs

@@ -20,6 +20,7 @@ internal class GlobalShortcutFocusBehavior : Behavior<Control>
         base.OnDetaching();
         AssociatedObject.GotFocus -= AssociatedObject_GotKeyboardFocus;
         AssociatedObject.LostFocus -= AssociatedObject_LostKeyboardFocus;
+        ShortcutController.UnblockShortcutExecution("GlobalShortcutFocusBehavior");
     }
 
     private void AssociatedObject_LostKeyboardFocus(object? sender, RoutedEventArgs routedEventArgs)

+ 8 - 0
src/PixiEditor/Helpers/DocumentViewModelBuilder.cs

@@ -88,6 +88,7 @@ internal class DocumentViewModelBuilder
         if (animationData != null && animationData.KeyFrameGroups.Count > 0)
         {
             AnimationData.WithFrameRate(animationData.FrameRate);
+            AnimationData.WithOnionFrames(animationData.OnionFrames);
             BuildKeyFrames(animationData.KeyFrameGroups.ToList(), AnimationData.KeyFrameGroups);
         }
 
@@ -194,12 +195,19 @@ internal class AnimationDataBuilder
 {
     public int FrameRate { get; set; } = 24;
     public List<KeyFrameBuilder> KeyFrameGroups { get; set; } = new List<KeyFrameBuilder>();
+    public int OnionFrames { get; set; }
 
     public AnimationDataBuilder WithFrameRate(int frameRate)
     {
         FrameRate = frameRate;
         return this;
     }
+    
+    public AnimationDataBuilder WithOnionFrames(int onionFrames)
+    {
+        OnionFrames = onionFrames;
+        return this;
+    }
 
     public AnimationDataBuilder WithKeyFrameGroups(Action<List<KeyFrameBuilder>> builder)
     {

+ 3 - 3
src/PixiEditor/Models/DocumentModels/DocumentUpdater.cs

@@ -199,7 +199,7 @@ internal class DocumentUpdater
             case FrameRate_ChangeInfo info:
                 ProcessFrameRate(info);
                 break;
-            case SetOnionFrames_PassthroughAction info:
+            case OnionFrames_ChangeInfo info:
                 ProcessSetOnionFrames(info);
                 break;
         }
@@ -618,8 +618,8 @@ internal class DocumentUpdater
         doc.AnimationHandler.SetFrameRate(info.NewFrameRate);
     }
     
-    private void ProcessSetOnionFrames(SetOnionFrames_PassthroughAction info)
+    private void ProcessSetOnionFrames(OnionFrames_ChangeInfo info)
     {
-        doc.AnimationHandler.SetOnionFrames(info.Frames);
+        doc.AnimationHandler.SetOnionFrames(info.OnionFrames);
     }
 }

+ 0 - 6
src/PixiEditor/Models/DocumentPassthroughActions/SetOnionFrames_PassthroughAction.cs

@@ -1,6 +0,0 @@
-using PixiEditor.ChangeableDocument.Actions;
-using PixiEditor.ChangeableDocument.ChangeInfos;
-
-namespace PixiEditor.Models.DocumentPassthroughActions;
-
-public record SetOnionFrames_PassthroughAction(int Frames) : IChangeInfo, IAction;

+ 1 - 1
src/PixiEditor/Models/Rendering/AffectedAreasGatherer.cs

@@ -140,7 +140,7 @@ internal class AffectedAreasGatherer
                 case ToggleOnionSkinning_PassthroughAction:
                     AddWholeCanvasToMainImage();
                     break;
-                case SetOnionFrames_PassthroughAction:
+                case OnionFrames_ChangeInfo:
                     AddWholeCanvasToMainImage();
                     break;
             }

+ 1 - 1
src/PixiEditor/ViewModels/Document/AnimationDataViewModel.cs

@@ -73,7 +73,7 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
             if (Document.UpdateableChangeActive)
                 return;
 
-            Internals.ActionAccumulator.AddFinishedActions(new SetOnionFrames_PassthroughAction(value));
+            Internals.ActionAccumulator.AddFinishedActions(new SetOnionFrames_Action(value));
         }
     }
 

+ 1 - 0
src/PixiEditor/ViewModels/Document/DocumentViewModel.Serialization.cs

@@ -209,6 +209,7 @@ internal partial class DocumentViewModel
         var animData = new AnimationData();
         animData.KeyFrameGroups = new List<KeyFrameGroup>();
         animData.FrameRate = animationData.FrameRate;
+        animData.OnionFrames = animationData.OnionFrames;
         BuildKeyFrames(animationData.KeyFrames, animData, graph, nodeIdMap, keyFrameIds);
 
         return animData;

+ 1 - 0
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -461,6 +461,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
                 return;
 
             acc.AddActions(new SetFrameRate_Action(data.FrameRate));
+            acc.AddActions(new SetOnionFrames_Action(data.OnionFrames));
             foreach (var keyFrame in data.KeyFrameGroups)
             {
                 if (keyFrame is GroupKeyFrameBuilder group)