draft: texture button
This commit is contained in:
@@ -8,4 +8,8 @@
|
||||
TaskName="GenerateProxyNodesTask"
|
||||
AssemblyFile="$(CustomTasksAssembly)"
|
||||
/>
|
||||
<UsingTask
|
||||
TaskName="ScanTextureSetFolderTask"
|
||||
AssemblyFile="$(CustomTasksAssembly)"
|
||||
/>
|
||||
</Project>
|
||||
@@ -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<MethodDeclarationSyntax> methods = cls.Members
|
||||
.OfType<MethodDeclarationSyntax>()
|
||||
@@ -55,6 +55,17 @@ public class GenerateProxyNodesTask : Task
|
||||
.SelectMany(a => a.Attributes)
|
||||
.Any(attr => attr.Name.ToString().Contains("ProxyMethod"))
|
||||
);
|
||||
IEnumerable<PropertyDeclarationSyntax> properties = cls.Members
|
||||
.OfType<PropertyDeclarationSyntax>()
|
||||
.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();
|
||||
|
||||
70
src/ScanTextureSetFolderTask.cs
Normal file
70
src/ScanTextureSetFolderTask.cs
Normal file
@@ -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<TextureSetName, TextureSet> 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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user