commit 8bf643f1948509fa2a0149a315ced9002df2741f Author: hzhang Date: Mon Feb 10 02:11:23 2025 +0000 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/.idea/.idea.Polonium.Tasks/.idea/.gitignore b/.idea/.idea.Polonium.Tasks/.idea/.gitignore new file mode 100644 index 0000000..0adbadb --- /dev/null +++ b/.idea/.idea.Polonium.Tasks/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.Polonium.Tasks.iml +/modules.xml +/projectSettingsUpdater.xml +/contentModel.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Polonium.Tasks.csproj b/Polonium.Tasks.csproj new file mode 100644 index 0000000..fdd7037 --- /dev/null +++ b/Polonium.Tasks.csproj @@ -0,0 +1,42 @@ + + + + netstandard2.0 + true + disable + latest + + true + + Polonium.Tasks + Polonium.Tasks + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + True + True + Resources.resx + + + + + + + + + diff --git a/Polonium.Tasks.sln b/Polonium.Tasks.sln new file mode 100644 index 0000000..48ca9b1 --- /dev/null +++ b/Polonium.Tasks.sln @@ -0,0 +1,24 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium.Tasks", "Polonium.Tasks.csproj", "{49610BA8-35D1-4185-AF6D-3DB5A7131DF8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49610BA8-35D1-4185-AF6D-3DB5A7131DF8}.Release|Any CPU.Build.0 = Release|Any CPU + {856F2142-B22B-43A9-86DD-4FD799CCA66B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {856F2142-B22B-43A9-86DD-4FD799CCA66B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {856F2142-B22B-43A9-86DD-4FD799CCA66B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {856F2142-B22B-43A9-86DD-4FD799CCA66B}.Release|Any CPU.Build.0 = Release|Any CPU + {B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2944CFE-84E9-4B8A-87E2-7113C5EA3A70}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Resources.Designer.cs b/Resources.Designer.cs new file mode 100644 index 0000000..58d8971 --- /dev/null +++ b/Resources.Designer.cs @@ -0,0 +1,88 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Polonium.Tasks +{ + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", + "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if (object.Equals(null, resourceMan)) + { + System.Resources.ResourceManager temp = + new System.Resources.ResourceManager("Polonium.Tasks.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture + { + get { return resourceCulture; } + set { resourceCulture = value; } + } + + internal static string AB0001Description + { + get { return ResourceManager.GetString("AB0001Description", resourceCulture); } + } + + internal static string AB0001MessageFormat + { + get { return ResourceManager.GetString("AB0001MessageFormat", resourceCulture); } + } + + internal static string AB0001Title + { + get { return ResourceManager.GetString("AB0001Title", resourceCulture); } + } + + internal static string AB0001CodeFixTitle + { + get { return ResourceManager.GetString("AB0001CodeFixTitle", resourceCulture); } + } + + internal static string AB0002Description + { + get { return ResourceManager.GetString("AB0002Description", resourceCulture); } + } + + internal static string AB0002MessageFormat + { + get { return ResourceManager.GetString("AB0002MessageFormat", resourceCulture); } + } + + internal static string AB0002Title + { + get { return ResourceManager.GetString("AB0002Title", resourceCulture); } + } + } +} \ No newline at end of file diff --git a/src/GenerateProxyNodesTask.cs b/src/GenerateProxyNodesTask.cs new file mode 100644 index 0000000..cf3505f --- /dev/null +++ b/src/GenerateProxyNodesTask.cs @@ -0,0 +1,85 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +namespace Polonium.Tasks; + +public class GenerateProxyNodesTask : Task +{ + [Required] + public string SourceDirectory { get; set; } + + [Required] + public string OutputDirectory { get; set; } + + [Required] + public string AttributeName { get; set; } + + public override bool Execute() + { + try + { + if(Directory.Exists(OutputDirectory)) + Directory.Delete(OutputDirectory, true); + Directory.CreateDirectory(OutputDirectory); + + string[] csFiles = Directory.GetFiles(SourceDirectory, "*.cs", SearchOption.AllDirectories); + foreach (string csFile in csFiles) + { + string code = File.ReadAllText(csFile); + SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); + CompilationUnitSyntax root = syntaxTree.GetCompilationUnitRoot(); + IEnumerable classes = root.DescendantNodes().OfType() + .Where(cls => cls.AttributeLists + .SelectMany(attrList => attrList.Attributes) + .Any(attr => attr.Name.ToString().Contains(AttributeName))); + + foreach (ClassDeclarationSyntax cls in classes) + { + string className = cls.Identifier.Text; + + StringBuilder sb = new StringBuilder(); + sb.AppendLine("using Godot;"); + sb.AppendLine($"namespace GlobalProxy {{"); + sb.AppendLine($" [GlobalClass]"); + sb.AppendLine($" [Tool]"); + sb.AppendLine($" public partial class {className} : {GetDisplayName(cls)} {{ }}"); + sb.AppendLine("}"); + + string outputFile = Path.Combine(OutputDirectory, $"{className}.cs"); + File.WriteAllText(outputFile, sb.ToString()); + Log.LogMessage(MessageImportance.High, $"Generated proxy file: {outputFile}"); + } + } + return true; + } + catch (Exception ex) + { + Log.LogErrorFromException(ex); + return false; + } + } + + private string GetDisplayName(ClassDeclarationSyntax cls) + { + string name = cls.Identifier.Text; + SyntaxNode node = cls.Parent; + while (node is not null) + { + if(node is NamespaceDeclarationSyntax ns) + name = ns.Name.ToString() + "." + name; + else if (node is FileScopedNamespaceDeclarationSyntax fs) + name = fs.Name.ToString() + "." + name; + node = node.Parent; + } + return name; + } + +} \ No newline at end of file