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