Browse Source

Added palettes and swatches import

flabbet 2 years ago
parent
commit
1892b31da5

+ 17 - 1
src/PixiEditor/Helpers/DocumentViewModelBuilder.cs

@@ -1,5 +1,6 @@
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
 using ChunkyImageLib;
 using ChunkyImageLib;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Surface;
 using PixiEditor.DrawingApi.Core.Surface;
 using BlendMode = PixiEditor.ChangeableDocument.Enums.BlendMode;
 using BlendMode = PixiEditor.ChangeableDocument.Enums.BlendMode;
@@ -9,8 +10,11 @@ namespace PixiEditor.Helpers;
 internal class DocumentViewModelBuilder : ChildrenBuilder
 internal class DocumentViewModelBuilder : ChildrenBuilder
 {
 {
     public int Width { get; set; }
     public int Width { get; set; }
-
     public int Height { get; set; }
     public int Height { get; set; }
+    
+    public List<Color> Swatches { get; set; } = new List<Color>();
+    public List<Color> Palette { get; set; } = new List<Color>();
+    
 
 
     public DocumentViewModelBuilder WithSize(int width, int height)
     public DocumentViewModelBuilder WithSize(int width, int height)
     {
     {
@@ -19,6 +23,18 @@ internal class DocumentViewModelBuilder : ChildrenBuilder
 
 
         return this;
         return this;
     }
     }
+    
+    public DocumentViewModelBuilder WithSwatches(List<Color> swatches)
+    {
+        Swatches = swatches;
+        return this;
+    }
+    
+    public DocumentViewModelBuilder WithPalette(List<Color> palette)
+    {
+        Palette = palette;
+        return this;
+    }
 
 
     public abstract class StructureMemberBuilder
     public abstract class StructureMemberBuilder
     {
     {

+ 7 - 3
src/PixiEditor/Helpers/Extensions/ParserHelpers.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Parser;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.Parser;
 using PixiEditor.Parser.Collections;
 using PixiEditor.Parser.Collections;
 using PixiEditor.ViewModels.SubViewModels.Document;
 using PixiEditor.ViewModels.SubViewModels.Document;
 
 
@@ -11,8 +12,11 @@ internal static class ParserHelpers
         List<SerializableLayer> builtLayers = new List<SerializableLayer>();
         List<SerializableLayer> builtLayers = new List<SerializableLayer>();
         DocumentViewModel vm = DocumentViewModel.Build(builder =>
         DocumentViewModel vm = DocumentViewModel.Build(builder =>
         {
         {
-            builder.WithSize(serializableDocument.Width, serializableDocument.Height);
-            
+            builder
+                .WithSize(serializableDocument.Width, serializableDocument.Height)
+                .WithPalette(serializableDocument.Palette.Select(x => new Color(x.R, x.G, x.B, x.A)).ToList())
+                .WithSwatches(serializableDocument.Swatches.Select(x => new Color(x.R, x.G, x.B, x.A)).ToList());
+
             if (serializableDocument.Groups != null)
             if (serializableDocument.Groups != null)
             {
             {
                 foreach (var group in serializableDocument.Groups)
                 foreach (var group in serializableDocument.Groups)

+ 1 - 1
src/PixiEditor/Models/DataHolders/Palettes/PaletteList.cs

@@ -2,7 +2,7 @@
 
 
 namespace PixiEditor.Models.DataHolders.Palettes;
 namespace PixiEditor.Models.DataHolders.Palettes;
 
 
-internal class PaletteList : NotifyableObject
+internal sealed class PaletteList : NotifyableObject
 {
 {
     public bool FetchedCorrectly { get; set; } = false;
     public bool FetchedCorrectly { get; set; } = false;
     public WpfObservableRangeCollection<Palette> Palettes { get; set; } = new WpfObservableRangeCollection<Palette>();
     public WpfObservableRangeCollection<Palette> Palettes { get; set; } = new WpfObservableRangeCollection<Palette>();

+ 3 - 0
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentViewModel.cs

@@ -191,6 +191,9 @@ internal class DocumentViewModel : NotifyableObject
 
 
         var acc = viewModel.Internals.ActionAccumulator;
         var acc = viewModel.Internals.ActionAccumulator;
 
 
+        viewModel.Swatches = new WpfObservableRangeCollection<Color>(builderInstance.Swatches);
+        viewModel.Palette = new WpfObservableRangeCollection<Color>(builderInstance.Palette);
+
         AddMembers(viewModel.StructureRoot.GuidValue, builderInstance.Children);
         AddMembers(viewModel.StructureRoot.GuidValue, builderInstance.Children);
 
 
         acc.AddFinishedActions(new DeleteRecordedChanges_Action());
         acc.AddFinishedActions(new DeleteRecordedChanges_Action());