From 44099d41d0bd7b0b6aadb7a99c624cf21a7e0867 Mon Sep 17 00:00:00 2001 From: hzhang Date: Sat, 15 Feb 2025 08:25:01 +0000 Subject: [PATCH 1/4] draft: texture button --- Package/build/Polonium.Tasks.props | 4 ++ src/GenerateProxyNodesTask.cs | 13 +++++- src/ScanTextureSetFolderTask.cs | 70 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/ScanTextureSetFolderTask.cs diff --git a/Package/build/Polonium.Tasks.props b/Package/build/Polonium.Tasks.props index 59ad64b..9fb025f 100644 --- a/Package/build/Polonium.Tasks.props +++ b/Package/build/Polonium.Tasks.props @@ -8,4 +8,8 @@ TaskName="GenerateProxyNodesTask" AssemblyFile="$(CustomTasksAssembly)" /> + \ No newline at end of file diff --git a/src/GenerateProxyNodesTask.cs b/src/GenerateProxyNodesTask.cs index 8cb00ce..b3279a5 100644 --- a/src/GenerateProxyNodesTask.cs +++ b/src/GenerateProxyNodesTask.cs @@ -47,7 +47,7 @@ public class GenerateProxyNodesTask : Task .AppendLine("// meta-default: true") .AppendLine("using _BINDINGS_NAMESPACE_;") .AppendLine("using System;") - .AppendLine("public partial class _CLASS_ : GlobalClasses._CLASS_") + .AppendLine($"public partial class _CLASS_ : {GetDisplayName(cls)}") .AppendLine("{"); IEnumerable methods = cls.Members .OfType() @@ -55,6 +55,17 @@ public class GenerateProxyNodesTask : Task .SelectMany(a => a.Attributes) .Any(attr => attr.Name.ToString().Contains("ProxyMethod")) ); + IEnumerable properties = cls.Members + .OfType() + .Where(m => m.AttributeLists + .SelectMany(a => a.Attributes) + .Any(attr => attr.Name.ToString().Contains("ProxyProperty")) + ); + foreach (PropertyDeclarationSyntax prop in properties) + { + sbx.AppendLine($" public override {prop.Type.ToString()} {prop.Identifier.ToString()} => base.{prop.Identifier.ToString()};"); + } + foreach (MethodDeclarationSyntax proxyMethod in methods) { string methodReturnType = proxyMethod.ReturnType.ToString(); diff --git a/src/ScanTextureSetFolderTask.cs b/src/ScanTextureSetFolderTask.cs new file mode 100644 index 0000000..3bddeeb --- /dev/null +++ b/src/ScanTextureSetFolderTask.cs @@ -0,0 +1,70 @@ +using System; +using System.IO; +using System.Text; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Polonium.Tasks; + +public class ScanTextureSetFolderTask : Task +{ + [Required] + public string RootPath { get; set; } + [Required] + public string OutputPath { get; set; } + + + public override bool Execute() + { + try + { + if (!Directory.Exists(RootPath)) + { + Log.LogError($"Root path does not exist: {RootPath}"); + return false; + } + + string[] textureSetDirs = Directory.GetDirectories(RootPath, "*.TextureSet", SearchOption.AllDirectories); + StringBuilder sb = new StringBuilder(); + StringBuilder sb1 = new StringBuilder(); + sb1 + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine("using Polonium.DataStructures;") + .AppendLine("public static partial class GlobalRegistry") + .AppendLine("{") + .AppendLine(" public static Dictionary TextureSetMap = new();") + .AppendLine(" public enum TextureSetName") + .AppendLine(" {"); + foreach (var dir in textureSetDirs) + { + + string relativePath = GetRelativePath(RootPath, dir); + sb.AppendLine($"res://Resources/ButtonTextureSet/{relativePath}"); + sb1.AppendLine($" {relativePath.Replace("/", "_").Replace(".TextureSet", "").Replace(".", "")},"); + } + sb1 + .AppendLine(" }") + .AppendLine("}"); + string outputPath = $"{OutputPath}textures_set.manifest"; + File.WriteAllText($"{OutputPath}Patches/TextureSetName.p.cs", sb1.ToString()); + File.WriteAllText(outputPath, sb.ToString()); + Log.LogMessage($"Output written to {outputPath}"); + + return true; + } + catch (Exception ex) + { + Log.LogErrorFromException(ex); + return false; + } + } + + private string GetRelativePath(string basePath, string fullPath) + { + Uri baseUri = new Uri(basePath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? basePath : basePath + Path.DirectorySeparatorChar); + Uri fullUri = new Uri(fullPath); + return Uri.UnescapeDataString(baseUri.MakeRelativeUri(fullUri).ToString().Replace('/', Path.DirectorySeparatorChar)); + } + +} \ No newline at end of file From f69ceb5f4d2ca52890501c6144dbf14258b52aec Mon Sep 17 00:00:00 2001 From: hzhang Date: Sun, 16 Feb 2025 22:36:38 +0000 Subject: [PATCH 2/4] refactor: redesign project structure --- Package/build/Polonium.Tasks.props | 4 +- Package/build/Polonium.Tasks.targets | 4 +- Polonium.Tasks.csproj | 4 +- src/GenerateProxyNodesTask.cs | 1 - src/GenerateTextureSetTask.cs | 113 +++++++++++++++++++++++++++ src/ScanTextureSetFolderTask.cs | 70 ----------------- 6 files changed, 121 insertions(+), 75 deletions(-) create mode 100644 src/GenerateTextureSetTask.cs delete mode 100644 src/ScanTextureSetFolderTask.cs diff --git a/Package/build/Polonium.Tasks.props b/Package/build/Polonium.Tasks.props index 9fb025f..3bb7cb2 100644 --- a/Package/build/Polonium.Tasks.props +++ b/Package/build/Polonium.Tasks.props @@ -9,7 +9,9 @@ AssemblyFile="$(CustomTasksAssembly)" /> + + \ No newline at end of file diff --git a/Package/build/Polonium.Tasks.targets b/Package/build/Polonium.Tasks.targets index 0dfb6a3..538978c 100644 --- a/Package/build/Polonium.Tasks.targets +++ b/Package/build/Polonium.Tasks.targets @@ -1,3 +1,5 @@ - + + + \ No newline at end of file diff --git a/Polonium.Tasks.csproj b/Polonium.Tasks.csproj index b7b9852..5001c6a 100644 --- a/Polonium.Tasks.csproj +++ b/Polonium.Tasks.csproj @@ -75,8 +75,8 @@ diff --git a/src/GenerateProxyNodesTask.cs b/src/GenerateProxyNodesTask.cs index b3279a5..8fcb57f 100644 --- a/src/GenerateProxyNodesTask.cs +++ b/src/GenerateProxyNodesTask.cs @@ -1,4 +1,3 @@ - using System; using System.Collections.Generic; using System.IO; diff --git a/src/GenerateTextureSetTask.cs b/src/GenerateTextureSetTask.cs new file mode 100644 index 0000000..759029a --- /dev/null +++ b/src/GenerateTextureSetTask.cs @@ -0,0 +1,113 @@ +using System; +using System.IO; +using System.Text; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Polonium.Tasks; + +public class GenerateTextureSetTask : Task +{ + [Required] + public string RootPath { get; set; } + [Required] + public string OutputPath { get; set; } + + + public override bool Execute() + { + try + { + if (!Directory.Exists(RootPath)) + { + Log.LogError($"Root path does not exist: {RootPath}"); + return false; + } + + string[] textureSetDirs = Directory.GetDirectories(RootPath, "*.TextureSet", SearchOption.AllDirectories); + StringBuilder sb = new StringBuilder(); + sb + .AppendLine("using System;") + .AppendLine("using Polonium.Attributes;") + .AppendLine("[AutoRegister]") + .AppendLine("public class TextureSetMapRegister") + .AppendLine("{") + .AppendLine(" public static void Register()") + .AppendLine(" {"); + StringBuilder sbx = new StringBuilder(); + sbx + .AppendLine("using System;") + .AppendLine("using System.Collections.Generic;") + .AppendLine("using Polonium.DataStructures;") + .AppendLine("public static partial class GlobalRegistry") + .AppendLine("{") + .AppendLine(" public static Dictionary TextureSetMap = new();") + .AppendLine(" public enum TextureSetName") + .AppendLine(" {"); + + foreach (string dir in textureSetDirs) + { + StringBuilder sby = new StringBuilder(); + sby + .AppendLine("using System;") + .AppendLine("using Polonium.DataStructures;") + .AppendLine("public static partial class GlobalRegistry") + .AppendLine("{") + .AppendLine(" public static partial class TextureSets") + .AppendLine(" {"); + string relativePath = GetRelativePath(RootPath, dir); + string godotPath = $"res://Resources/ButtonTextureSet/{relativePath}"; + string lName = relativePath.Replace("/", "_").Replace(".TextureSet", "").Replace(".", ""); + string[] parts = relativePath.Split('/'); + string instanceName = parts[parts.Length - 1].Replace(".TextureSet", ""); + string instanceFullName = "GlobalRegistry.TextureSets"; + string indent = " "; + StringBuilder sbsy = new StringBuilder(); + foreach (string part in parts) + { + if (part == parts[parts.Length - 1]) + break; + sby + .AppendLine($"{indent}public static partial class {part}") + .AppendLine($"{indent}{{"); + sbsy.Insert(0, $"{indent}}}"); + instanceFullName += $".{part}"; + indent += " "; + } + instanceFullName += $".{instanceName}"; + sby + .AppendLine($"{indent} public static readonly TextureSet {instanceName} = new TextureSet(\"{godotPath}\");") + .Append(sbsy) + .AppendLine(" }") + .AppendLine("}"); + File.WriteAllText($"{OutputPath}Patches/{lName}.p.cs", sby.ToString()); + sbx.AppendLine($" {lName},"); + sb.AppendLine($" GlobalRegistry.TextureSetMap[GlobalRegistry.TextureSetName.{lName}] = {instanceFullName};"); + } + sbx + .AppendLine(" }") + .AppendLine("}"); + sb + .AppendLine(" }") + .AppendLine("}"); + File.WriteAllText($"{OutputPath}Patches/TextureSetName.p.cs", sbx.ToString()); + + File.WriteAllText($"{OutputPath}Patches/TextureSetMapRegister.p.cs", sb.ToString()); + + return true; + } + catch (Exception ex) + { + Log.LogErrorFromException(ex); + return false; + } + } + + private string GetRelativePath(string basePath, string fullPath) + { + Uri baseUri = new Uri(basePath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? basePath : basePath + Path.DirectorySeparatorChar); + Uri fullUri = new Uri(fullPath); + return Uri.UnescapeDataString(baseUri.MakeRelativeUri(fullUri).ToString().Replace('/', Path.DirectorySeparatorChar)); + } + +} \ No newline at end of file diff --git a/src/ScanTextureSetFolderTask.cs b/src/ScanTextureSetFolderTask.cs deleted file mode 100644 index 3bddeeb..0000000 --- a/src/ScanTextureSetFolderTask.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.IO; -using System.Text; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; - -namespace Polonium.Tasks; - -public class ScanTextureSetFolderTask : Task -{ - [Required] - public string RootPath { get; set; } - [Required] - public string OutputPath { get; set; } - - - public override bool Execute() - { - try - { - if (!Directory.Exists(RootPath)) - { - Log.LogError($"Root path does not exist: {RootPath}"); - return false; - } - - string[] textureSetDirs = Directory.GetDirectories(RootPath, "*.TextureSet", SearchOption.AllDirectories); - StringBuilder sb = new StringBuilder(); - StringBuilder sb1 = new StringBuilder(); - sb1 - .AppendLine("using System;") - .AppendLine("using System.Collections.Generic;") - .AppendLine("using Polonium.DataStructures;") - .AppendLine("public static partial class GlobalRegistry") - .AppendLine("{") - .AppendLine(" public static Dictionary TextureSetMap = new();") - .AppendLine(" public enum TextureSetName") - .AppendLine(" {"); - foreach (var dir in textureSetDirs) - { - - string relativePath = GetRelativePath(RootPath, dir); - sb.AppendLine($"res://Resources/ButtonTextureSet/{relativePath}"); - sb1.AppendLine($" {relativePath.Replace("/", "_").Replace(".TextureSet", "").Replace(".", "")},"); - } - sb1 - .AppendLine(" }") - .AppendLine("}"); - string outputPath = $"{OutputPath}textures_set.manifest"; - File.WriteAllText($"{OutputPath}Patches/TextureSetName.p.cs", sb1.ToString()); - File.WriteAllText(outputPath, sb.ToString()); - Log.LogMessage($"Output written to {outputPath}"); - - return true; - } - catch (Exception ex) - { - Log.LogErrorFromException(ex); - return false; - } - } - - private string GetRelativePath(string basePath, string fullPath) - { - Uri baseUri = new Uri(basePath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? basePath : basePath + Path.DirectorySeparatorChar); - Uri fullUri = new Uri(fullPath); - return Uri.UnescapeDataString(baseUri.MakeRelativeUri(fullUri).ToString().Replace('/', Path.DirectorySeparatorChar)); - } - -} \ No newline at end of file From 4d3d06f8d18e01b7b20e59795f7ccf603ec27d58 Mon Sep 17 00:00:00 2001 From: hzhang Date: Mon, 17 Feb 2025 02:49:21 +0000 Subject: [PATCH 3/4] refactor: redesign project structures --- Package/build/Polonium.Tasks.props | 6 ------ Package/build/Polonium.Tasks.targets | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Package/build/Polonium.Tasks.props b/Package/build/Polonium.Tasks.props index 3bb7cb2..59ad64b 100644 --- a/Package/build/Polonium.Tasks.props +++ b/Package/build/Polonium.Tasks.props @@ -8,10 +8,4 @@ TaskName="GenerateProxyNodesTask" AssemblyFile="$(CustomTasksAssembly)" /> - - - \ No newline at end of file diff --git a/Package/build/Polonium.Tasks.targets b/Package/build/Polonium.Tasks.targets index 538978c..d9e80ec 100644 --- a/Package/build/Polonium.Tasks.targets +++ b/Package/build/Polonium.Tasks.targets @@ -2,4 +2,27 @@ + + + + + + + + + + + + + + + \ No newline at end of file From dce78db64ce95f938a857866a1293fdf3829f7b6 Mon Sep 17 00:00:00 2001 From: hzhang Date: Tue, 18 Feb 2025 11:41:05 +0000 Subject: [PATCH 4/4] add: sdk --- Package/build/Polonium.Tasks.props | 15 ++++++++----- Package/build/Polonium.Tasks.targets | 26 ++-------------------- Polonium.Tasks.csproj | 32 ++++++---------------------- 3 files changed, 18 insertions(+), 55 deletions(-) diff --git a/Package/build/Polonium.Tasks.props b/Package/build/Polonium.Tasks.props index 59ad64b..5064ec7 100644 --- a/Package/build/Polonium.Tasks.props +++ b/Package/build/Polonium.Tasks.props @@ -1,11 +1,16 @@ + - $(MSBuildThisFileDirectory)tasks/netstandard2.0/ - $(CustomTasksFolder)$(MSBuildThisFileName).dll + $(MSBuildThisFileDirectory)tasks/netstandard2.0/ + $(TasksFolder)$(MSBuildThisFileName).dll - + \ No newline at end of file diff --git a/Package/build/Polonium.Tasks.targets b/Package/build/Polonium.Tasks.targets index d9e80ec..6df0c26 100644 --- a/Package/build/Polonium.Tasks.targets +++ b/Package/build/Polonium.Tasks.targets @@ -1,28 +1,6 @@ - - + + - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Polonium.Tasks.csproj b/Polonium.Tasks.csproj index 5001c6a..35956b3 100644 --- a/Polonium.Tasks.csproj +++ b/Polonium.Tasks.csproj @@ -33,37 +33,21 @@ Version="4.12.0" PrivateAssets="all" /> - - - ResXFileCodeGenerator Resources.Designer.cs - - - True True Resources.resx - - - - - - - - - + + @@ -102,8 +86,4 @@ - - - -