Compare commits

...

10 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
2812d98d15 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Polonium.Generators.csproj
2025-02-06 01:43:35 +00:00
2f3e5ad146 improve: rename project 2025-02-06 01:33:12 +00:00
17 changed files with 139 additions and 62 deletions

13
.idea/.idea.Polonium.Generators/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/modules.xml
/.idea.Hangman.SDK.Generators.iml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

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

View File

@@ -1,3 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=Hangman_002ESDK_002EGenerators_002FResources/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

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

@@ -0,0 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.1.1-x</Version>
<Authors>Hangman</Authors>
<PackageId>Polonium.Generators</PackageId>
<DisableImplicitRestore>true</DisableImplicitRestore>
</PropertyGroup>
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers\dotnet\cs" Link="Package\analyzers\dotnet\cs\$(AssemblyName).dll" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0"/>
</ItemGroup>
<Target Name="CleanPreviousPackages" BeforeTargets="Build">
<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>

View File

@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hangman.SDK.Generators", "Hangman.SDK.Generators.csproj", "{884B5A6A-4063-4FC7-8FE6-EE1C45CF251E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polonium.Generators", "Polonium.Generators.csproj", "{884B5A6A-4063-4FC7-8FE6-EE1C45CF251E}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=Hangman_002ESDK_002EGenerators_002FResources/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"DebugRoslynSourceGenerator": {
"commandName": "DebugRoslynComponent",
"targetProject": "../Polonium.Generators.Test/Polonium.Generators.Test.csproj"
}
}
}

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;
@@ -21,4 +21,5 @@ public struct AssetInfo
} }
public string ScenePath => GodotPath.Replace(".cs", ".tscn"); public string ScenePath => GodotPath.Replace(".cs", ".tscn");
} }

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