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:
@@ -5,7 +5,6 @@
|
||||
<IsPackable>true</IsPackable>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
<IsRoslynComponent>true</IsRoslynComponent>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
@@ -43,7 +42,7 @@
|
||||
<Copy SourceFiles="@(NuGetPackages)" DestinationFolder="/NuGetFeed"/>
|
||||
</Target>
|
||||
|
||||
<Target Name="RestoreNoCache" BeforeTargets="Restore">
|
||||
<Target Name="RestoreNoCache" BeforeTargets="CoreCompile">
|
||||
<Message Text="Restoring packages with no chache" Importance="high"/>
|
||||
<Exec Command="dotnet restore --no-cache"/>
|
||||
</Target>
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Polonium.Generators.Generators;
|
||||
[Generator]
|
||||
public class GlobalRegistryGenerator : ISourceGenerator
|
||||
{
|
||||
public void Initialize(GeneratorInitializationContext context)
|
||||
{
|
||||
}
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb
|
||||
.AppendLine("using Godot;")
|
||||
.AppendLine("using System;")
|
||||
.AppendLine("using System.Collections.Generic;")
|
||||
.AppendLine("using System.Linq;")
|
||||
.AppendLine("using System.Reflection;")
|
||||
.AppendLine("using Polonium.Attributes;")
|
||||
.AppendLine("using Polonium;")
|
||||
.AppendLine("using Polonium.Interfaces;")
|
||||
.AppendLine("public static partial class GlobalRegistry")
|
||||
.AppendLine("{")
|
||||
.AppendLine(" public static void Start()")
|
||||
.AppendLine(" {")
|
||||
.AppendLine(" PoloniumRegistry.Prepare();")
|
||||
.AppendLine(" Assembly assembly = Assembly.GetExecutingAssembly();")
|
||||
.AppendLine(" IEnumerable<Type> registerTypes = Utils.GetLoadableTypes(assembly);")
|
||||
.AppendLine(" registerTypes = registerTypes.Where(t => t.IsClass && t.GetCustomAttributes(typeof(AutoRegister), false).Any());")
|
||||
.AppendLine(" foreach(Type t in registerTypes)")
|
||||
.AppendLine(" {")
|
||||
.AppendLine(" MethodInfo registerMethod = t.GetMethod(\"Register\", BindingFlags.Static | BindingFlags.Public);")
|
||||
.AppendLine(" if (registerMethod != null)")
|
||||
.AppendLine(" registerMethod.Invoke(null, null);")
|
||||
.AppendLine(" }")
|
||||
.AppendLine(" }")
|
||||
.AppendLine(" public static class Asset<T> where T : Node")
|
||||
.AppendLine(" {")
|
||||
.AppendLine(" private static readonly Queue<T> Pool = new();")
|
||||
.AppendLine(" public static PackedScene Scene { get; set; }")
|
||||
.AppendLine(" public static T Instance => Scene.Instantiate<T>();")
|
||||
.AppendLine(" public static T Get() => Pool.Count > 0 ? Pool.Dequeue() : Instance;")
|
||||
.AppendLine(" public static void Return(T obj)")
|
||||
.AppendLine(" {")
|
||||
.AppendLine(" if(Pool.Count < 10)")
|
||||
.AppendLine(" Pool.Enqueue(obj);")
|
||||
.AppendLine(" else")
|
||||
.AppendLine(" obj.QueueFree();")
|
||||
.AppendLine(" }")
|
||||
.AppendLine(" }")
|
||||
.AppendLine(" public static PoloniumRegistry PoloniumRegistry => PoloniumRegistry.Instance;")
|
||||
.AppendLine(" public static bool Paused { get; set; }")
|
||||
.AppendLine(" public static HashSet<ITimeConsumer> TimeConsumers { get; } = new ();")
|
||||
.AppendLine("}");
|
||||
context.AddSource("GlobalRegistry.g.cs", sb.ToString());
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace Polonium.Generators.Generators;
|
||||
[Generator]
|
||||
public class ProxyNodeGenerator : AssetProcessGenerator
|
||||
{
|
||||
private INamedTypeSymbol? NodeProxy { get; set; }
|
||||
|
||||
private IEnumerable<INamedTypeSymbol> ProxyNodesInNamespace(INamespaceSymbol ns)
|
||||
{
|
||||
foreach (INamespaceOrTypeSymbol member in ns.GetMembers())
|
||||
{
|
||||
if (member is INamespaceSymbol nsx)
|
||||
foreach (INamedTypeSymbol nsz in ProxyNodesInNamespace(nsx))
|
||||
yield return nsz;
|
||||
else if (member is INamedTypeSymbol nsu)
|
||||
if (nsu.GetAttributes().Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, NodeProxy)))
|
||||
yield return nsu;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
Compilation compilation = context.Compilation;
|
||||
NodeProxy = compilation.GetTypeByMetadataName("Polonium.Attributes.ProxyNode");
|
||||
foreach (INamedTypeSymbol node in ProxyNodesInNamespace(compilation.GlobalNamespace))
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb
|
||||
.AppendLine($"namespace Polonium.Nodes;")
|
||||
.AppendLine("using Godot;")
|
||||
.AppendLine($"[GlobalClass]")
|
||||
.AppendLine($"[Tool]")
|
||||
.AppendLine($"public partial class {node.Name} : {node.ToDisplayString()}")
|
||||
.AppendLine("{")
|
||||
.AppendLine("}");
|
||||
context.AddSource($"NodeProxy_{node.Name}.g.cs", sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user