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" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<CustomTasksFolder>$(MSBuildThisFileDirectory)tasks/netstandard2.0/</CustomTasksFolder>
|
<TasksFolder>$(MSBuildThisFileDirectory)tasks/netstandard2.0/</TasksFolder>
|
||||||
<CustomTasksAssembly>$(CustomTasksFolder)$(MSBuildThisFileName).dll</CustomTasksAssembly>
|
<TasksAssembly>$(TasksFolder)$(MSBuildThisFileName).dll</TasksAssembly>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<UsingTask
|
<UsingTask
|
||||||
TaskName="GenerateProxyNodesTask"
|
TaskName="GenerateProxyNodesTask"
|
||||||
AssemblyFile="$(CustomTasksAssembly)"
|
AssemblyFile="$(TasksAssembly)"
|
||||||
|
/>
|
||||||
|
<UsingTask
|
||||||
|
TaskName="GenerateTextureSetTask"
|
||||||
|
AssemblyFile="$(TasksAssembly)"
|
||||||
/>
|
/>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Target Name="CheckTasksAssembly" BeforeTargets="CoreCompile">
|
||||||
|
<Message Text="TasksAssembly: $(TasksAssembly)" Importance="High" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -33,37 +33,21 @@
|
|||||||
Version="4.12.0"
|
Version="4.12.0"
|
||||||
PrivateAssets="all"
|
PrivateAssets="all"
|
||||||
/>
|
/>
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Update="Resources.resx">
|
<EmbeddedResource Update="Resources.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Update="Resources.Designer.cs">
|
<Compile Update="Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md" />
|
||||||
|
<AdditionalFiles Remove="AnalyzerReleases.Unshipped.md" />
|
||||||
<ItemGroup>
|
<None
|
||||||
<AdditionalFiles Remove="AnalyzerReleases.Shipped.md" />
|
Include="Package/build/**/*"
|
||||||
<AdditionalFiles Remove="AnalyzerReleases.Unshipped.md" />
|
Pack="true"
|
||||||
</ItemGroup>
|
PackagePath="build"
|
||||||
<ItemGroup>
|
|
||||||
<None
|
|
||||||
Include="Package\build\$(AssemblyName).targets"
|
|
||||||
Pack="true"
|
|
||||||
PackagePath="build"
|
|
||||||
/>
|
|
||||||
<None
|
|
||||||
Include="Package\build\$(AssemblyName).props"
|
|
||||||
Pack="true"
|
|
||||||
PackagePath="build"
|
|
||||||
/>
|
/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
|
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
|
||||||
@@ -75,8 +59,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
<Target
|
<Target
|
||||||
Name="AddBuildDependencyFileToBuiltProjectOutputGroupOutput"
|
Name="AddBuildDependencyFileToBuiltProjectOutputGroupOutput"
|
||||||
BeforeTargets="BuiltProjectOutputGroup"
|
BeforeTargets="BuiltProjectOutputGroup"
|
||||||
Condition="'$(GenerateDependencyFile)' == 'true'"
|
Condition="'$(GenerateDependencyFile)' == 'true'"
|
||||||
>
|
>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -102,8 +86,4 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Copy SourceFiles="@(NuGetPackages)" DestinationFolder="/NuGetFeed"/>
|
<Copy SourceFiles="@(NuGetPackages)" DestinationFolder="/NuGetFeed"/>
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="RestoreNoCache" BeforeTargets="Build">
|
|
||||||
<Message Text="Restoring packages with no chache" Importance="high"/>
|
|
||||||
<Exec Command="dotnet restore --no-cache"/>
|
|
||||||
</Target>
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -47,7 +46,7 @@ public class GenerateProxyNodesTask : Task
|
|||||||
.AppendLine("// meta-default: true")
|
.AppendLine("// meta-default: true")
|
||||||
.AppendLine("using _BINDINGS_NAMESPACE_;")
|
.AppendLine("using _BINDINGS_NAMESPACE_;")
|
||||||
.AppendLine("using System;")
|
.AppendLine("using System;")
|
||||||
.AppendLine("public partial class _CLASS_ : GlobalClasses._CLASS_")
|
.AppendLine($"public partial class _CLASS_ : {GetDisplayName(cls)}")
|
||||||
.AppendLine("{");
|
.AppendLine("{");
|
||||||
IEnumerable<MethodDeclarationSyntax> methods = cls.Members
|
IEnumerable<MethodDeclarationSyntax> methods = cls.Members
|
||||||
.OfType<MethodDeclarationSyntax>()
|
.OfType<MethodDeclarationSyntax>()
|
||||||
@@ -55,6 +54,17 @@ public class GenerateProxyNodesTask : Task
|
|||||||
.SelectMany(a => a.Attributes)
|
.SelectMany(a => a.Attributes)
|
||||||
.Any(attr => attr.Name.ToString().Contains("ProxyMethod"))
|
.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)
|
foreach (MethodDeclarationSyntax proxyMethod in methods)
|
||||||
{
|
{
|
||||||
string methodReturnType = proxyMethod.ReturnType.ToString();
|
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