Compare commits
8 Commits
2812d98d15
...
draft_text
| Author | SHA1 | Date | |
|---|---|---|---|
| e97b2f098f | |||
| 6738080639 | |||
| 24a74a6f80 | |||
| a34fca7581 | |||
| 6683b6252c | |||
| cdf94b3e0c | |||
| 59529419e5 | |||
| a52ebfa2f2 |
@@ -1,54 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using Microsoft.CodeAnalysis;
|
|
||||||
|
|
||||||
namespace Polonium.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("public static partial class GlobalRegistry")
|
|
||||||
.AppendLine("{")
|
|
||||||
.AppendLine(" public static void Register()")
|
|
||||||
.AppendLine(" {")
|
|
||||||
.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("}");
|
|
||||||
context.AddSource("GlobalRegistry.g.cs", sb.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8
NuGet.config
Normal file
8
NuGet.config
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<add key="hangman-lab" value="https://git.hangman-lab.top/api/packages/hzhang/nuget/index.json"/>
|
||||||
|
<add key="Local" value="/NuGetFeed"/>
|
||||||
|
</packageSources>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
<IsPackable>true</IsPackable>
|
<IsPackable>true</IsPackable>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
|
|
||||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||||
<IsRoslynComponent>true</IsRoslynComponent>
|
<IsRoslynComponent>true</IsRoslynComponent>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Version>0.0.2</Version>
|
<Version>0.1.1-x</Version>
|
||||||
<Authors>Hangman</Authors>
|
<Authors>Hangman</Authors>
|
||||||
<PackageId>Polonium.Generators</PackageId>
|
<PackageId>Polonium.Generators</PackageId>
|
||||||
|
<DisableImplicitRestore>true</DisableImplicitRestore>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -24,8 +24,26 @@
|
|||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0"/>
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<Target Name="CleanPreviousPackages" BeforeTargets="Build">
|
||||||
<Content Include="Polonium.Generators.sln.DotSettings.user" />
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<ExistingPackages Include="$(OutputPath)../*.nupkg"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<Delete Files="@(ExistingPackages)" ContinueOnError="true"/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="CopyPackageToLocalFeed" AfterTargets="Pack">
|
||||||
|
<Message Text="Executing Copy Pack Task" Importance="high" />
|
||||||
|
<Message Text="OutputPath: $(ProjectDir)$(OutputPath)" Importance="high" />
|
||||||
|
<ItemGroup>
|
||||||
|
<NuGetPackages Include="$(OutputPath)../*.nupkg" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Message Text="Printing pkgs--------------------" Importance="high"/>
|
||||||
|
<Message Text="Pkgs: @(NuGetPackages)" Importance="high"/>
|
||||||
|
<Copy SourceFiles="@(NuGetPackages)" DestinationFolder="/NuGetFeed"/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="RestoreNoCache" BeforeTargets="CoreCompile">
|
||||||
|
<Message Text="Restoring packages with no chache" Importance="high"/>
|
||||||
|
<Exec Command="dotnet restore --no-cache"/>
|
||||||
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
2
publish
2
publish
@@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
dotnet nuget push "$(ls -t ./bin/Debug/Hangman.SDK.Generators.*.nupkg | head -n 1)" --source hangman-lab
|
dotnet nuget push "$(ls -t ./bin/Debug/Polonium.Generators.*.nupkg | head -n 1)" --source hangman-lab
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
namespace Polonium.Generators;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
|
namespace Polonium.Generators;
|
||||||
|
|
||||||
public struct AssetInfo
|
public struct AssetInfo
|
||||||
{
|
{
|
||||||
public INamedTypeSymbol Symbol;
|
public INamedTypeSymbol Symbol;
|
||||||
@@ -5,7 +5,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
namespace Polonium.Generators;
|
namespace Polonium.Generators.Generators;
|
||||||
[Generator]
|
[Generator]
|
||||||
public class AssetRegisterGenerator : AssetProcessGenerator
|
public class AssetRegisterGenerator : AssetProcessGenerator
|
||||||
{
|
{
|
||||||
33
src/Generators/RegistryEntityGenerator.cs
Normal file
33
src/Generators/RegistryEntityGenerator.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Polonium.Generators.Generators;
|
||||||
|
[Generator]
|
||||||
|
public class RegistryEntityGenerator : AssetProcessGenerator
|
||||||
|
{
|
||||||
|
public override void Execute(GeneratorExecutionContext context)
|
||||||
|
{
|
||||||
|
if (!(context.SyntaxReceiver is ClassSyntaxReceiver receiver))
|
||||||
|
return;
|
||||||
|
Compilation compilation = context.Compilation;
|
||||||
|
INamedTypeSymbol? regEntity = compilation.GetTypeByMetadataName("Polonium.Attributes.RegistryEntity");
|
||||||
|
foreach (var derivedClassDeclaration in receiver.Classes)
|
||||||
|
{
|
||||||
|
SemanticModel model = compilation.GetSemanticModel(derivedClassDeclaration.SyntaxTree);
|
||||||
|
if (
|
||||||
|
model.GetDeclaredSymbol(derivedClassDeclaration) is INamedTypeSymbol symbol &&
|
||||||
|
symbol.GetAttributes().Any(x => SymbolEqualityComparer.Default.Equals(x.AttributeClass, regEntity))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new();
|
||||||
|
sb
|
||||||
|
.AppendLine("public static partial class GlobalRegistry")
|
||||||
|
.AppendLine("{")
|
||||||
|
.AppendLine($" public static {symbol.ToDisplayString()} {symbol.Name} {{ get; set; }} ")
|
||||||
|
.AppendLine("}");
|
||||||
|
context.AddSource($"RegistryEntity_{symbol.Name}.g.cs", sb.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user