Ver código fonte

Implemented PixiParser support

flabbet 4 anos atrás
pai
commit
a52057910a

+ 49 - 36
PixiEditor/Helpers/Extensions/ParserHelpers.cs

@@ -5,12 +5,11 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows;
 using System.Windows.Media;
-using PixiEditor.Models.DataHolders;
-using PixiEditor.Models.ImageManipulation;
-using PixiEditor.Models.Layers;
 using PixiEditor.Parser;
 using SDColor = System.Drawing.Color;
-
+using PixiEditor.Parser.Models;
+using System;
+
 namespace PixiEditor.Helpers.Extensions
 {
     public static class ParserHelpers
@@ -24,6 +23,8 @@ namespace PixiEditor.Helpers.Extensions
                     Color.FromArgb(x.A, x.R, x.G, x.B)))
             };
 
+            document.LayerStructure.Groups = serializableDocument.ToGroups();
+
             if (document.Layers.Count > 0)
             {
                 document.SetMainActiveLayer(0);
@@ -32,7 +33,40 @@ namespace PixiEditor.Helpers.Extensions
             return document;
         }
 
-        public static ObservableCollection<Layer> ToLayers(this Parser.SerializableDocument serializableDocument)
+        public static ObservableCollection<GuidStructureItem> ToGroups(this SerializableDocument serializableDocument)
+        {
+            return ToGroups(serializableDocument.Groups);
+        }
+
+        private static ObservableCollection<GuidStructureItem> ToGroups(SerializableGuidStructureItem[] serializableGroups)
+        {
+            ObservableCollection<GuidStructureItem> groups = new ObservableCollection<GuidStructureItem>();
+
+            if (serializableGroups == null)
+            {
+                return groups;
+            }
+
+            foreach (var serializableGroup in serializableGroups)
+            {
+                groups.Add(ToGroup(serializableGroup));
+            }
+            return groups;
+        }
+
+        private static GuidStructureItem ToGroup(SerializableGuidStructureItem group)
+        {
+            if (group == null) return null;
+            return new GuidStructureItem(
+                    group.Name,
+                    group.StartLayerGuid,
+                    group.EndLayerGuid,
+                    ToGroups(group.Subgroups),
+                    ToGroup(group.Parent))
+                    { Opacity = group.Opacity, IsVisible = group.IsVisible, GroupGuid = group.GroupGuid };
+        }
+
+        public static ObservableCollection<Layer> ToLayers(this SerializableDocument serializableDocument)
         {
             ObservableCollection<Layer> layers = new ObservableCollection<Layer>();
             for (int i = 0; i < serializableDocument.Layers.Count; i++)
@@ -46,40 +80,17 @@ namespace PixiEditor.Helpers.Extensions
                         Opacity = serLayer.Opacity,
                         MaxHeight = serializableDocument.Height,
                         MaxWidth = serializableDocument.Width,
-                    };
+                    };
+                if (serLayer.LayerGuid != Guid.Empty)
+                {
+                    layer.ChangeGuid(serLayer.LayerGuid);
+                }
                 layers.Add(layer);
             }
 
             return layers;
         }
 
-        /*public static ObservableCollection<GuidStructureItem> ToGroups(this Parser.SerializableDocument serializableDocument)
-        {
-            return ToGroups(serializableDocument.Groups);
-        }
-
-        private static ObservableCollection<GuidStructureItem> ToGroups(SerializableGuidStructureItem[] items)
-        {
-            ObservableCollection<GuidStructureItem> groups = new();
-
-            for (int i = 0; i < items.Length; i++)
-            {
-                SerializableGuidStructureItem item = items[i];
-                groups.Add(ToGroup(item));
-            }
-            return groups;
-        }
-
-        private static GuidStructureItem ToGroup(SerializableGuidStructureItem item)
-        {
-            return new GuidStructureItem(
-                item.Name,
-                item.StartLayerGuid,
-                item.EndLayerGuid,
-                ToGroups(item.Subgroups),
-                ToGroup(item.Parent));
-        }*/
-
         public static SerializableDocument ToSerializable(this Document document)
         {
             Parser.SerializableDocument serializable = new Parser.SerializableDocument
@@ -87,13 +98,14 @@ namespace PixiEditor.Helpers.Extensions
                 Width = document.Width,
                 Height = document.Height,
                 Layers = document.Layers.Select(x => x.ToSerializable()).ToList(),
+                Groups = document.LayerStructure.Groups.Select(x => x.ToSerializable()).ToArray(),
                 Swatches = document.Swatches.Select(x => SDColor.FromArgb(x.A, x.R, x.G, x.B)).ToList()
             };
 
             return serializable;
         }
 
-        /*public static SerializableGuidStructureItem ToSerializable(this GuidStructureItem group)
+        public static SerializableGuidStructureItem ToSerializable(this GuidStructureItem group)
         {
             return new(
                     group.GroupGuid,
@@ -101,13 +113,14 @@ namespace PixiEditor.Helpers.Extensions
                     group.StartLayerGuid,
                     group.EndLayerGuid,
                     group.Subgroups.Select(x => x.ToSerializable()).ToArray(),
-                    group.Parent?.ToSerializable());
-        }*/
+                    group.Parent?.ToSerializable(), group.IsVisible, group.Opacity);
+        }
 
         public static Parser.SerializableLayer ToSerializable(this Layer layer)
         {
             Parser.SerializableLayer serializable = new Parser.SerializableLayer
             {
+                LayerGuid = layer.LayerGuid,
                 Name = layer.Name,
                 Width = layer.Width,
                 Height = layer.Height,

+ 2 - 8
PixiEditor/Models/Layers/GuidStructureItem.cs

@@ -70,10 +70,7 @@ namespace PixiEditor.Models.Layers
         public bool IsRenaming
         {
             get => isRenaming;
-            set
-            {
-                SetProperty(ref isRenaming, value);
-            }
+            set => SetProperty(ref isRenaming, value);
         }
 
         private bool isVisible = true;
@@ -81,10 +78,7 @@ namespace PixiEditor.Models.Layers
         public bool IsVisible
         {
             get => isVisible;
-            set
-            {
-                SetProperty(ref isVisible, value);
-            }
+            set => SetProperty(ref isVisible, value);
         }
 
         private float opacity = 1;

+ 1 - 1
PixiEditor/PixiEditor.csproj

@@ -152,7 +152,7 @@
     <PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
     <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
     <PackageReference Include="PixiEditor.ColorPicker" Version="3.1.0" />
-    <PackageReference Include="PixiEditor.Parser" Version="1.1.2.1" />
+    <PackageReference Include="PixiEditor.Parser" Version="1.1.3" />
     <PackageReference Include="WriteableBitmapEx">
       <Version>1.6.7</Version>
     </PackageReference>

+ 1 - 1
PixiEditor/Views/UserControls/LayerItem.xaml.cs

@@ -63,7 +63,7 @@ namespace PixiEditor.Views
 
         public string LayerName
         {
-            get { return (string) GetValue(LayerNameProperty); }
+            get { return (string)GetValue(LayerNameProperty); }
             set { SetValue(LayerNameProperty, value); }
         }
 

+ 7 - 8
PixiEditor/Views/UserControls/LayersManager.xaml.cs

@@ -53,14 +53,6 @@ namespace PixiEditor.Views.UserControls
         public LayersManager()
         {
             InitializeComponent();
-        }
-
-        private void LayerStructureItemContainer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
-        {
-            if (sender is LayerStructureItemContainer container && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
-            {
-                DragDrop.DoDragDrop(container, container, DragDropEffects.Move);
-            }
         }
 
         private static void ItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
@@ -90,6 +82,13 @@ namespace PixiEditor.Views.UserControls
             }
         }
 
+        private void LayerStructureItemContainer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
+        {
+            if (sender is LayerStructureItemContainer container && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
+            {
+                DragDrop.DoDragDrop(container, container, DragDropEffects.Move);
+            }
+        }
 
         private void HandleGroupOpacityChange(LayerGroup group, float value)
         {