Merge pull request 'draft_texture_button' (#1) from draft_texture_button into master

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
h z
2025-02-18 14:30:12 +00:00
5 changed files with 147 additions and 36 deletions

View File

@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CustomTasksFolder>$(MSBuildThisFileDirectory)tasks/netstandard2.0/</CustomTasksFolder>
<CustomTasksAssembly>$(CustomTasksFolder)$(MSBuildThisFileName).dll</CustomTasksAssembly>
<TasksFolder>$(MSBuildThisFileDirectory)tasks/netstandard2.0/</TasksFolder>
<TasksAssembly>$(TasksFolder)$(MSBuildThisFileName).dll</TasksAssembly>
</PropertyGroup>
<UsingTask
TaskName="GenerateProxyNodesTask"
AssemblyFile="$(CustomTasksAssembly)"
<UsingTask
TaskName="GenerateProxyNodesTask"
AssemblyFile="$(TasksAssembly)"
/>
<UsingTask
TaskName="GenerateTextureSetTask"
AssemblyFile="$(TasksAssembly)"
/>
</Project>

View File

@@ -1,3 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CheckTasksAssembly" BeforeTargets="CoreCompile">
<Message Text="TasksAssembly: $(TasksAssembly)" Importance="High" />
</Target>
</Project>

View File

@@ -33,37 +33,21 @@
Version="4.12.0"
PrivateAssets="all"
/>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Remove="AnalyzerReleases.Unshipped.md" />
</ItemGroup>
<ItemGroup>
<None
Include="Package\build\$(AssemblyName).targets"
Pack="true"
PackagePath="build"
/>
<None
Include="Package\build\$(AssemblyName).props"
Pack="true"
PackagePath="build"
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Remove="AnalyzerReleases.Unshipped.md" />
<None
Include="Package/build/**/*"
Pack="true"
PackagePath="build"
/>
</ItemGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
@@ -75,8 +59,8 @@
</ItemGroup>
</Target>
<Target
Name="AddBuildDependencyFileToBuiltProjectOutputGroupOutput"
BeforeTargets="BuiltProjectOutputGroup"
Name="AddBuildDependencyFileToBuiltProjectOutputGroupOutput"
BeforeTargets="BuiltProjectOutputGroup"
Condition="'$(GenerateDependencyFile)' == 'true'"
>
<ItemGroup>
@@ -102,8 +86,4 @@
</ItemGroup>
<Copy SourceFiles="@(NuGetPackages)" DestinationFolder="/NuGetFeed"/>
</Target>
<Target Name="RestoreNoCache" BeforeTargets="Build">
<Message Text="Restoring packages with no chache" Importance="high"/>
<Exec Command="dotnet restore --no-cache"/>
</Target>
</Project>

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
@@ -47,7 +46,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 +54,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();

View File

@@ -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<TextureSetName, TextureSet> 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));
}
}