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:
@@ -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)"
|
||||
AssemblyFile="$(TasksAssembly)"
|
||||
/>
|
||||
<UsingTask
|
||||
TaskName="GenerateTextureSetTask"
|
||||
AssemblyFile="$(TasksAssembly)"
|
||||
/>
|
||||
</Project>
|
||||
@@ -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>
|
||||
@@ -33,35 +33,19 @@
|
||||
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"
|
||||
Include="Package/build/**/*"
|
||||
Pack="true"
|
||||
PackagePath="build"
|
||||
/>
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
113
src/GenerateTextureSetTask.cs
Normal file
113
src/GenerateTextureSetTask.cs
Normal 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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user