Compare commits

..

8 Commits

Author SHA1 Message Date
e97b2f098f add: sdk 2025-02-18 11:41:05 +00:00
6738080639 refactor: redesign project structure 2025-02-16 22:36:38 +00:00
24a74a6f80 draft: texture button 2025-02-15 08:25:01 +00:00
a34fca7581 refactor: move global classes def into package 2025-02-14 13:31:11 +00:00
6683b6252c add: dissolve scene / nuget feed source 2025-02-12 23:37:50 +00:00
cdf94b3e0c add: LoadingScene, ProxyNode 2025-02-09 01:07:12 +00:00
59529419e5 improve: move to src 2025-02-07 02:30:40 +00:00
a52ebfa2f2 add: Template for Save and config 2025-02-07 02:29:37 +00:00
9 changed files with 68 additions and 63 deletions

View File

@@ -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
View 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>

View File

@@ -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>
<Target Name="CleanPreviousPackages" BeforeTargets="Build">
<ItemGroup> <ItemGroup>
<Content Include="Polonium.Generators.sln.DotSettings.user" /> <ExistingPackages Include="$(OutputPath)../*.nupkg"/>
</ItemGroup> </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>

View File

@@ -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

View File

@@ -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;

View File

@@ -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
{ {

View 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());
}
}
}
}