Browse Source

Fixed empty font family serialization and localized node enums

Krzysztof Krysiński 4 months ago
parent
commit
fb368a0502

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 1f966ffb17a8f2140c4b0d95e5e318880a4b53e5
+Subproject commit 7e4de2359281d40b99049748d7056f6cd836fbde

+ 4 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/TileNode.cs

@@ -15,8 +15,8 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 public class TileNode : RenderNode
 {
     public InputProperty<Texture> Image { get; }
-    public InputProperty<ShaderTileMode> TileModeX { get; }
-    public InputProperty<ShaderTileMode> TileModeY { get; }
+    public InputProperty<TileMode> TileModeX { get; }
+    public InputProperty<TileMode> TileModeY { get; }
     public InputProperty<Matrix3X3> Matrix { get; }
 
     private Drawie.Backend.Core.Surfaces.ImageData.Image lastImage;
@@ -26,8 +26,8 @@ public class TileNode : RenderNode
     public TileNode()
     {
         Image = CreateInput<Texture>("Image", "IMAGE", null);
-        TileModeX = CreateInput<ShaderTileMode>("TileModeX", "TILE_MODE_X", ShaderTileMode.Repeat);
-        TileModeY = CreateInput<ShaderTileMode>("TileModeY", "TILE_MODE_Y", ShaderTileMode.Repeat);
+        TileModeX = CreateInput<TileMode>("TileModeX", "TILE_MODE_X", TileMode.Repeat);
+        TileModeY = CreateInput<TileMode>("TileModeY", "TILE_MODE_Y", TileMode.Repeat);
         Matrix = CreateInput<Matrix3X3>("Matrix", "MATRIX", Matrix3X3.Identity);
 
         Output.FirstInChain = null;

+ 14 - 1
src/PixiEditor.Extensions/Helpers/EnumHelpers.cs

@@ -41,7 +41,7 @@ public static class EnumHelpers
         if (fieldInfo != null)
         {
             var attrs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
-            if (attrs != null && attrs.Length > 0)
+            if (attrs is { Length: > 0 })
             {
                 description = ((DescriptionAttribute)attrs[0]).Description;
             }
@@ -49,4 +49,17 @@ public static class EnumHelpers
 
         return description;
     }
+
+    public static bool HasDescription(Enum enumValue)
+    {
+        var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
+
+        if (fieldInfo != null)
+        {
+            var attrs = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
+            return attrs is { Length: > 0 };
+        }
+
+        return false;
+    }
 }

+ 58 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -924,5 +924,62 @@
   "EASING_NODE": "Easing",
   "EASING_TYPE": "Easing Type",
   "OPEN_DIRECTORY_ON_EXPORT": "Open directory on export",
-  "ERROR_LOOP_DETECTED_MESSAGE": "Moving this layer will create a loop. Fix it in the Node Graph."
+  "ERROR_LOOP_DETECTED_MESSAGE": "Moving this layer will create a loop. Fix it in the Node Graph.",
+  "LINEAR_EASING_TYPE": "Linear",
+  "IN_SINE_EASING_TYPE": "In Sine",
+  "OUT_SINE_EASING_TYPE": "Out Sine",
+  "IN_OUT_SINE_EASING_TYPE": "In Out Sine",
+  "IN_QUAD_EASING_TYPE": "In Quad",
+  "OUT_QUAD_EASING_TYPE": "Out Quad",
+  "IN_OUT_QUAD_EASING_TYPE": "In Out Quad",
+  "IN_CUBIC_EASING_TYPE": "In Cubic",
+  "OUT_CUBIC_EASING_TYPE": "Out Cubic",
+  "IN_OUT_CUBIC_EASING_TYPE": "In Out Cubic",
+  "IN_QUART_EASING_TYPE": "In Quart",
+  "OUT_QUART_EASING_TYPE": "Out Quart",
+  "IN_OUT_QUART_EASING_TYPE": "In Out Quart",
+  "IN_QUINT_EASING_TYPE": "In Quint",
+  "OUT_QUINT_EASING_TYPE": "Out Quint",
+  "IN_OUT_QUINT_EASING_TYPE": "In Out Quint",
+  "IN_EXPO_EASING_TYPE": "In Expo",
+  "OUT_EXPO_EASING_TYPE": "Out Expo",
+  "IN_OUT_EXPO_EASING_TYPE": "In Out Expo",
+  "IN_CIRC_EASING_TYPE": "In Circ",
+  "OUT_CIRC_EASING_TYPE": "Out Circ",
+  "IN_OUT_CIRC_EASING_TYPE": "In Out Circ",
+  "IN_BACK_EASING_TYPE": "In Back",
+  "OUT_BACK_EASING_TYPE": "Out Back",
+  "IN_OUT_BACK_EASING_TYPE": "In Out Back",
+  "IN_ELASTIC_EASING_TYPE": "In Elastic",
+  "OUT_ELASTIC_EASING_TYPE": "Out Elastic",
+  "IN_OUT_ELASTIC_EASING_TYPE": "In Out Elastic",
+  "IN_BOUNCE_EASING_TYPE": "In Bounce",
+  "OUT_BOUNCE_EASING_TYPE": "Out Bounce",
+  "IN_OUT_BOUNCE_EASING_TYPE": "In Out Bounce",
+  "CLAMP_SHADER_TILE_NODE": "Clamp",
+  "REPEAT_SHADER_TILE_NODE": "Repeat",
+  "MIRROR_SHADER_TILE_NODE": "Mirror",
+  "DECAL_SHADER_TILE_NODE": "Decal",
+  "R_G_B_COMBINE_SEPARATE_COLOR_MODE": "RGB",
+  "H_S_V_COMBINE_SEPARATE_COLOR_MODE": "HSV",
+  "H_S_L_COMBINE_SEPARATE_COLOR_MODE": "HSL",
+  "COLOR_MANAGED_COLOR_SAMPLE_MODE": "Color Managed",
+  "RAW_COLOR_SAMPLE_MODE": "Raw",
+  "FRACTAL_PERLIN_NOISE_TYPE": "Perlin",
+  "TURBULENCE_PERLIN_NOISE_TYPE": "Turbulence",
+  "INHERIT_COLOR_SPACE_TYPE": "Inherit",
+  "SRGB_COLOR_SPACE_TYPE": "sRGB",
+  "LINEAR_SRGB_COLOR_SPACE_TYPE": "Linear sRGB",
+  "SIMPLE_OUTLINE_TYPE": "Simple",
+  "GAUSSIAN_OUTLINE_TYPE": "Gaussian",
+  "PIXEL_PERFECT_OUTLINE_TYPE": "Pixel Perfect",
+  "DEGREES_ROTATION_TYPE": "Degrees",
+  "RADIANS_ROTATION_TYPE": "Radians",
+  "WEIGHTED_GRAYSCALE_MODE": "Weighted",
+  "AVERAGE_GRAYSCALE_MODE": "Average",
+  "CUSTOM_GRAYSCALE_MODE": "Custom",
+  "CLAMP_TILE_MODE": "Clamp",
+  "REPEAT_TILE_MODE": "Repeat",
+  "MIRROR_TILE_MODE": "Mirror",
+  "DECAL_TILE_MODE": "Decal"
 }

+ 18 - 1
src/PixiEditor/Helpers/Converters/EnumToLocalizedStringConverter.cs

@@ -9,9 +9,26 @@ internal class EnumToLocalizedStringConverter : SingleInstanceConverter<EnumToLo
     {
         if (value is Enum enumValue)
         {
-            return EnumHelpers.GetDescription(enumValue);
+            if (EnumHelpers.HasDescription(enumValue))
+            {
+                return EnumHelpers.GetDescription(enumValue);
+            }
+
+            return ToLocalizedStringFormat(enumValue);
         }
 
         return value;
     }
+
+    private string ToLocalizedStringFormat(Enum enumValue)
+    {
+        // VALUE_ENUMTYPE
+        // for example BlendMode.Normal becomes NORMAL_BLEND_MODE
+
+        string enumType = enumValue.GetType().Name;
+
+        string value = enumValue.ToString();
+
+        return $"{value.ToSnakeCase()}_{enumType.ToSnakeCase()}".ToUpper();
+    }
 }

+ 32 - 0
src/PixiEditor/Helpers/StringHelpers.cs

@@ -17,6 +17,7 @@ internal static class StringHelpers
                 newText.Append(' ');
             newText.Append(text[i]);
         }
+
         return newText.ToString();
     }
 
@@ -24,4 +25,35 @@ internal static class StringHelpers
     {
         return value.Length > maxLenght ? value.Substring(0, maxLenght) : value;
     }
+
+    public static string ToSnakeCase(this string text)
+    {
+        if (text == null)
+        {
+            throw new ArgumentNullException(nameof(text));
+        }
+
+        if (text.Length < 2)
+        {
+            return text.ToLowerInvariant();
+        }
+
+        var sb = new StringBuilder();
+        sb.Append(char.ToLowerInvariant(text[0]));
+        for (int i = 1; i < text.Length; ++i)
+        {
+            char c = text[i];
+            if (char.IsUpper(c))
+            {
+                sb.Append('_');
+                sb.Append(char.ToLowerInvariant(c));
+            }
+            else
+            {
+                sb.Append(c);
+            }
+        }
+
+        return sb.ToString();
+    }
 }

+ 5 - 0
src/PixiEditor/Models/Serialization/Factories/FontFamilySerializationFactory.cs

@@ -11,6 +11,11 @@ public class FontFamilySerializationFactory : SerializationFactory<byte[], FontF
     {
         ByteBuilder builder = new ByteBuilder();
 
+        if (original.Name == null)
+        {
+            original = new FontFamilyName(FontLibrary.DefaultFontFamily.Name) { FontUri = original.FontUri };
+        }
+
         builder.AddString(original.Name);
         builder.AddBool(original.FontUri?.IsFile ?? false);
         if (original.FontUri?.IsFile ?? false)

+ 7 - 1
src/PixiEditor/ViewModels/Document/Nodes/FilterNodes/KernelFilterNodeViewModel.cs

@@ -4,4 +4,10 @@ using PixiEditor.ViewModels.Nodes;
 namespace PixiEditor.ViewModels.Document.Nodes.FilterNodes;
 
 [NodeViewModel("KERNEL_FILTER_NODE", "FILTERS", "\uE80F")]
-internal class KernelFilterNodeViewModel : NodeViewModel<KernelFilterNode>;
+internal class KernelFilterNodeViewModel : NodeViewModel<KernelFilterNode>
+{
+    public override void OnInitialized()
+    {
+
+    }
+}

+ 2 - 1
src/PixiEditor/Views/Rendering/Scene.cs

@@ -34,6 +34,7 @@ using PixiEditor.Views.Visuals;
 using Bitmap = Drawie.Backend.Core.Surfaces.Bitmap;
 using Color = Drawie.Backend.Core.ColorsImpl.Color;
 using Point = Avalonia.Point;
+using TileMode = Drawie.Backend.Core.Surfaces.TileMode;
 
 namespace PixiEditor.Views.Rendering;
 
@@ -281,7 +282,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
         {
             Shader = Shader.CreateBitmap(
                 checkerBitmap,
-                ShaderTileMode.Repeat, ShaderTileMode.Repeat,
+                TileMode.Repeat, TileMode.Repeat,
                 Matrix3X3.CreateScale(checkerScale, checkerScale)),
             FilterQuality = FilterQuality.None
         };