Browse Source

Added protogen

flabbet 1 year ago
parent
commit
1a41b54490

+ 13 - 0
src/PixiEditor.Extensions.CommonApi/.config/dotnet-tools.json

@@ -0,0 +1,13 @@
+{
+  "version": 1,
+  "isRoot": true,
+  "tools": {
+    "protobuf-net.protogen": {
+      "version": "3.2.42",
+      "commands": [
+        "protogen"
+      ],
+      "rollForward": false
+    }
+  }
+}

+ 14 - 0
src/PixiEditor.Extensions.CommonApi/DataContracts/ExtensionPalette.proto

@@ -0,0 +1,14 @@
+syntax = "proto3";
+package PixiEditor.Palettes;
+
+import "PaletteColor.proto";
+
+option csharp_namespace = "PixiEditor.Extensions.CommonApi.Palettes";
+
+message ExtensionPalette
+{
+  string Name = 1;
+  repeated PixiEditor.Palettes.PaletteColor Colors = 2;
+  bool IsFavourite = 3;
+  string FileName = 4;
+}

+ 11 - 0
src/PixiEditor.Extensions.CommonApi/DataContracts/PaletteColor.proto

@@ -0,0 +1,11 @@
+syntax = "proto3";
+package PixiEditor.Palettes;
+
+option csharp_namespace = "PixiEditor.Extensions.CommonApi.Palettes";
+
+message PaletteColor
+{
+  uint32 R_Value = 1;
+  uint32 G_Value = 2;
+  uint32 B_Value = 3;
+}

+ 11 - 0
src/PixiEditor.Extensions.CommonApi/DataContracts/PaletteListResult.proto

@@ -0,0 +1,11 @@
+syntax = "proto3";
+package PixiEditor.Palettes;
+
+import "ExtensionPalette.proto";
+
+option csharp_namespace = "PixiEditor.Extensions.CommonApi.Palettes";
+
+message PaletteListResult
+{
+    repeated ExtensionPalette Palettes = 1;  
+}

+ 13 - 0
src/PixiEditor.Extensions.CommonApi/Palettes/ExtensionPalette.Impl.cs

@@ -0,0 +1,13 @@
+namespace PixiEditor.Extensions.CommonApi.Palettes;
+
+public partial class ExtensionPalette : IPalette
+{
+    public PaletteListDataSource Source { get; set; }
+    
+    public ExtensionPalette(string name, List<PaletteColor> colors, PaletteListDataSource source)
+    {
+        Name = name;
+        Colors = colors;
+        Source = source;
+    }
+}

+ 0 - 33
src/PixiEditor.Extensions.CommonApi/Palettes/ExtensionPalette.cs

@@ -1,33 +0,0 @@
-using ProtoBuf;
-
-namespace PixiEditor.Extensions.CommonApi.Palettes;
-
-[ProtoContract]
-public class ExtensionPalette : IPalette
-{
-    [ProtoMember(1)]
-    public string Name { get; }
-    
-    [ProtoMember(2)]
-    public List<PaletteColor> Colors { get; }
-    
-    [ProtoMember(3)]
-    public bool IsFavourite { get; set; }
-    
-    [ProtoMember(4)]
-    public string FileName { get; set; }
-    
-    [ProtoIgnore]
-    public PaletteListDataSource Source { get; set; }
-
-    public ExtensionPalette(string name, List<PaletteColor> colors, PaletteListDataSource source)
-    {
-        Name = name;
-        Colors = colors;
-        Source = source;
-    }
-    
-    public ExtensionPalette()
-    {
-    }
-}

+ 34 - 21
src/PixiEditor.Extensions.CommonApi/Palettes/PaletteColor.cs → src/PixiEditor.Extensions.CommonApi/Palettes/PaletteColor.Impl.cs

@@ -1,32 +1,45 @@
-using ProtoBuf;
+namespace PixiEditor.Extensions.CommonApi.Palettes;
 
-namespace PixiEditor.Extensions.CommonApi.Palettes;
-
-[ProtoContract]
-public struct PaletteColor
+public partial class PaletteColor
 {
-    public static PaletteColor Empty => new(0, 0, 0);
-    public static PaletteColor Black => new(0, 0, 0);
-    public static PaletteColor White => new(255, 255, 255);
-    
-    [ProtoMember(1)]
-    public byte R { get; set; }
+    public static PaletteColor Empty => new PaletteColor(0, 0, 0);
+    public static PaletteColor Black => new PaletteColor(0, 0, 0);
+    public static PaletteColor White => new PaletteColor(255, 255, 255);
+
+    public byte R
+    {
+        get => (byte)RValue;
+        set => RValue = value;
+    }
+
+    public byte G
+    {
+        get => (byte)GValue;
+        set => GValue = value;
+    }
     
-    [ProtoMember(2)]
-    public byte G { get; set; }
+    public byte B
+    {
+        get => (byte)BValue;
+        set => BValue = value;
+    }
     
-    [ProtoMember(3)]
-    public byte B { get; set; }
-
     public string Hex => $"#{R:X2}{G:X2}{B:X2}";
-
+    
     public PaletteColor(byte r, byte g, byte b)
     {
-        R = r;
-        G = g;
-        B = b;
+        RValue = r;
+        GValue = g;
+        BValue = b;
     }
-
+    
+    public PaletteColor(uint r, uint g, uint b)
+    {
+        RValue = (byte)r;
+        GValue = (byte)g;
+        BValue = (byte)b;
+    }
+    
     public override string ToString()
     {
         return Hex;

+ 9 - 0
src/PixiEditor.Extensions.CommonApi/Palettes/PaletteListResult.Impl.cs

@@ -0,0 +1,9 @@
+namespace PixiEditor.Extensions.CommonApi.Palettes;
+
+public partial class PaletteListResult
+{
+    public PaletteListResult(IEnumerable<ExtensionPalette> palettes)
+    {
+        Palettes = new List<ExtensionPalette>(palettes);
+    }
+}

+ 0 - 20
src/PixiEditor.Extensions.CommonApi/Palettes/PaletteListResult.cs

@@ -1,20 +0,0 @@
-using System.Runtime.Serialization;
-using ProtoBuf;
-
-namespace PixiEditor.Extensions.CommonApi.Palettes;
-
-[ProtoContract]
-public class PaletteListResult
-{
-    [ProtoMember(1)]
-    public ExtensionPalette[] Palettes { get; set; }
-
-    public PaletteListResult(ExtensionPalette[] palettes)
-    {
-        Palettes = palettes;
-    }
-    
-    public PaletteListResult()
-    {
-    }
-}

+ 1 - 1
src/PixiEditor.Extensions.CommonApi/Palettes/Parsers/PaletteFileData.cs

@@ -36,7 +36,7 @@ public class PaletteFileData
         for (int i = 0; i < Colors.Length; i++)
         {
             PaletteColor color = Colors[i];
-            colors[i] = new PaletteColor(color.R, color.G, color.B);
+            colors[i] = new PaletteColor((byte)color.R, (byte)color.G, (byte)color.B);
         }
 
         return colors;

+ 39 - 0
src/PixiEditor.Extensions.CommonApi/PixiEditor.Extensions.CommonApi.csproj

@@ -13,5 +13,44 @@
     <ItemGroup>
       <PackageReference Include="protobuf-net" Version="3.2.30" />
     </ItemGroup>
+  
+  <PropertyGroup>
+    <ProtogenVersion>3.2.42</ProtogenVersion>
+  </PropertyGroup>
+  
+  <Target Name="ProtogenCheck" BeforeTargets="GenerateProtoContracts">
+    <PropertyGroup>
+      <ProtogenExists>false</ProtogenExists>
+    </PropertyGroup>
+    <Exec Command="dotnet tool run protogen --version" IgnoreExitCode="true">
+      <Output TaskParameter="ExitCode" PropertyName="ProtogenExitCode"/>
+    </Exec>
+    <PropertyGroup>
+      <ProtogenExists Condition="'$(ProtogenExitCode)' == '0'">true</ProtogenExists>
+    </PropertyGroup>
+  </Target>
+  
+  <Target Name="InstallProtogen" BeforeTargets="GenerateProtoContracts"
+          Condition="'$(ProtogenExists)' != 'true'">
+    <Message Text="Downloading protogen v$(ProtogenVersion)..." Importance="high"/>
+    <Exec Command="dotnet tool install --local protobuf-net.Protogen --version $(ProtogenVersion)"/>
+    <PropertyGroup>
+      <ProtogenExists>true</ProtogenExists>
+    </PropertyGroup>
+    
+    <Message Text="protogen installed successfully." Importance="high"/>
+  </Target>
+    
+  
+  <Target Name="GenerateProtoContracts" BeforeTargets="BeforeCompile"
+          Inputs="$(MSBuildProjectDirectory)\DataContracts\*.proto"
+          Outputs="$(MSBuildProjectDirectory)\ProtoAutogen\*.cs">
+    <Exec Command="dotnet tool run protogen --csharp_out=ProtoAutogen --proto_path=DataContracts *.proto"/>
+
+    <ItemGroup>
+      <Compile Include="ProtoAutogen\*.cs" KeepDuplicates="false"/>
+    </ItemGroup>
+
+  </Target>
 
 </Project>

+ 38 - 0
src/PixiEditor.Extensions.CommonApi/ProtoAutogen/ExtensionPalette.cs

@@ -0,0 +1,38 @@
+// <auto-generated>
+//   This file was generated by a tool; you should avoid making direct changes.
+//   Consider using 'partial classes' to extend these types
+//   Input: ExtensionPalette.proto
+// </auto-generated>
+
+#region Designer generated code
+#pragma warning disable CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
+namespace PixiEditor.Extensions.CommonApi.Palettes
+{
+
+    [global::ProtoBuf.ProtoContract()]
+    public partial class ExtensionPalette : global::ProtoBuf.IExtensible
+    {
+        private global::ProtoBuf.IExtension __pbn__extensionData;
+        global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
+            => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
+
+        [global::ProtoBuf.ProtoMember(1)]
+        [global::System.ComponentModel.DefaultValue("")]
+        public string Name { get; set; } = "";
+
+        [global::ProtoBuf.ProtoMember(2)]
+        public global::System.Collections.Generic.List<PaletteColor> Colors { get; } = new global::System.Collections.Generic.List<PaletteColor>();
+
+        [global::ProtoBuf.ProtoMember(3)]
+        public bool IsFavourite { get; set; }
+
+        [global::ProtoBuf.ProtoMember(4)]
+        [global::System.ComponentModel.DefaultValue("")]
+        public string FileName { get; set; } = "";
+
+    }
+
+}
+
+#pragma warning restore CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
+#endregion

+ 33 - 0
src/PixiEditor.Extensions.CommonApi/ProtoAutogen/PaletteColor.cs

@@ -0,0 +1,33 @@
+// <auto-generated>
+//   This file was generated by a tool; you should avoid making direct changes.
+//   Consider using 'partial classes' to extend these types
+//   Input: PaletteColor.proto
+// </auto-generated>
+
+#region Designer generated code
+#pragma warning disable CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
+namespace PixiEditor.Extensions.CommonApi.Palettes
+{
+
+    [global::ProtoBuf.ProtoContract()]
+    public partial class PaletteColor : global::ProtoBuf.IExtensible
+    {
+        private global::ProtoBuf.IExtension __pbn__extensionData;
+        global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
+            => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
+
+        [global::ProtoBuf.ProtoMember(1, Name = @"R_Value")]
+        public uint RValue { get; set; }
+
+        [global::ProtoBuf.ProtoMember(2, Name = @"G_Value")]
+        public uint GValue { get; set; }
+
+        [global::ProtoBuf.ProtoMember(3, Name = @"B_Value")]
+        public uint BValue { get; set; }
+
+    }
+
+}
+
+#pragma warning restore CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
+#endregion

+ 27 - 0
src/PixiEditor.Extensions.CommonApi/ProtoAutogen/PaletteListResult.cs

@@ -0,0 +1,27 @@
+// <auto-generated>
+//   This file was generated by a tool; you should avoid making direct changes.
+//   Consider using 'partial classes' to extend these types
+//   Input: PaletteListResult.proto
+// </auto-generated>
+
+#region Designer generated code
+#pragma warning disable CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
+namespace PixiEditor.Extensions.CommonApi.Palettes
+{
+
+    [global::ProtoBuf.ProtoContract()]
+    public partial class PaletteListResult : global::ProtoBuf.IExtensible
+    {
+        private global::ProtoBuf.IExtension __pbn__extensionData;
+        global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
+            => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
+
+        [global::ProtoBuf.ProtoMember(1)]
+        public global::System.Collections.Generic.List<ExtensionPalette> Palettes { get; } = new global::System.Collections.Generic.List<ExtensionPalette>();
+
+    }
+
+}
+
+#pragma warning restore CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
+#endregion

+ 15 - 0
src/PixiEditor.Extensions.CommonApi/ProtoAutogen/README.md

@@ -0,0 +1,15 @@
+# DO NOT MODIFY .CS FILES IN THIS DIRECTORY
+
+They are autogenerated from the .proto files. If you want to make changes to them, 
+please modify the .proto files and build project.
+
+Protogen is installed on first build, but if you want to install it manually, you can do it by installing protobuf-net.Protogen nuget package.
+To install it globally on your machine go to https://www.nuget.org/packages/protobuf-net.Protogen and follow .NET CLI (Global) instructions.
+
+For example `dotnet tool install --global protobuf-net.Protogen --version 3.2.42`
+
+After installing protogen, you can run it by executing `protogen` in the root directory of PixiEditor.Extensions.CommonApi
+
+```bash
+protogen --csharp_out=ProtoAutogen --proto_path=DataContracts *.proto
+```

+ 0 - 4
src/PixiEditor.Extensions.Sdk/build/PixiEditor.Extensions.Sdk.targets

@@ -1,8 +1,4 @@
 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <!-- <Target Name="GenerateLayouts" AfterTargets="Build" Inputs="bin\Debug\$(TargetFramework)\PixiEditor.Extensions.Sdk.dll" Outputs="$(RootFolder)\Layouts\">
-    <Exec  ConsoleToMSBuild="true"
-          Command="..\PixiEditor.Extensions.MSBuildLayoutCompiler\bin\Debug\net8.0\PixiEditor.Extensions.MSBuildLayoutCompiler.exe $(OutputPath)\$(MSBuildProjectName).dll $(OutputPath)\Layouts\"/>
-  </Target>-->
 
   <UsingTask TaskName="GenerateCGlueTask"
              AssemblyFile="$(MSBuildThisFileDirectory)PixiEditor.Api.CGlueMSBuild.dll" Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'"/>