Compare commits
No commits in common. "1ee021029b7a95cd87fe027c150caa282537b2c3" and "44c3d49aad08611e9f32f0ad5821195228796b26" have entirely different histories.
1ee021029b
...
44c3d49aad
11 changed files with 59 additions and 148 deletions
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Godot.Sharp.Extended.Attributes;
|
|
||||||
|
|
||||||
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
|
|
||||||
public class NodeBindAttribute : Attribute
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
namespace Godot.Sharp.Extended.Attributes;
|
|
||||||
|
|
||||||
[System.AttributeUsage(System.AttributeTargets.Field)]
|
|
||||||
public class NodePropBindAttribute : System.Attribute
|
|
||||||
{
|
|
||||||
public string TargetNodeName { get; private set; }
|
|
||||||
public string GodotPropertyName { get; private set; }
|
|
||||||
|
|
||||||
public NodePropBindAttribute(string targetNodeName, string godotPropertyName)
|
|
||||||
{
|
|
||||||
TargetNodeName = targetNodeName;
|
|
||||||
GodotPropertyName = godotPropertyName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
namespace Godot.Sharp.Extended.Attributes;
|
|
||||||
|
|
||||||
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
|
|
||||||
public class ResourcePathAttribute : System.Attribute
|
|
||||||
{
|
|
||||||
public string Path { get; private set; }
|
|
||||||
|
|
||||||
public ResourcePathAttribute(string path) {
|
|
||||||
Path = path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<PackageId>Godot.Sharp.Extended</PackageId>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="GodotSharp" Version="4.4.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
namespace Godot.Sharp.Extended.Tools;
|
|
||||||
|
|
||||||
public static partial class MathFunctionExtensions
|
|
||||||
{
|
|
||||||
public static bool InRange(this int @this, int min, int max) => @this >= min && @this <= max;
|
|
||||||
public static bool InRange(this float @this, float min, float max) => @this >= min && @this <= max;
|
|
||||||
public static bool InRange(this double @this, double min, double max) => @this >= min && @this <= max;
|
|
||||||
public static bool InRange(this Vector2 @this, Vector2 min, Vector2 max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y);
|
|
||||||
public static bool InRange(this Vector2I @this, Vector2I min, Vector2I max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y);
|
|
||||||
public static bool InRange(this Vector3 @this, Vector3 min, Vector3 max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y) && @this.Z.InRange(min.Z, max.Z);
|
|
||||||
public static bool InRange(this Vector3I @this, Vector3I min, Vector3I max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y) && @this.Z.InRange(min.Z, max.Z);
|
|
||||||
public static bool InRange(this Vector4 @this, Vector4 min, Vector4 max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y) && @this.Z.InRange(min.Z, max.Z) && @this.W.InRange(min.W, max.W);
|
|
||||||
public static bool InRange(this Vector4I @this, Vector4I min, Vector4I max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y) && @this.Z.InRange(min.Z, max.Z) && @this.W.InRange(min.W, max.W);
|
|
||||||
public static bool InRange(this Quaternion @this, Quaternion min, Quaternion max) =>
|
|
||||||
@this.X.InRange(min.X, max.X) && @this.Y.InRange(min.Y, max.Y) && @this.Z.InRange(min.Z, max.Z) && @this.W.InRange(min.W, max.W);
|
|
||||||
}
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
using Godot.Collections;
|
|
||||||
|
|
||||||
namespace Godot.Sharp.Extended.Tools;
|
|
||||||
|
|
||||||
public static class NodeExtensions
|
|
||||||
{
|
|
||||||
public static void AddToGroup(this Node node) => node.AddToGroup(node.GetType().Name);
|
|
||||||
public static T GetNode<T>(this Node node) where T : Node => node.GetNode<T>(typeof(T).Name);
|
|
||||||
public static Array<T> GetChildrenOfType<T>(this Node node) where T : Node
|
|
||||||
{
|
|
||||||
var children = node.GetChildren();
|
|
||||||
|
|
||||||
return new Array<T>(children.OfType<T>().ToArray());
|
|
||||||
}
|
|
||||||
public static T? GetFirstChildOfType<T>(this Node node) where T : Node => GetChildrenOfType<T>(node).FirstOrDefault();
|
|
||||||
|
|
||||||
public static void RemoveAllChildren(this Node node)
|
|
||||||
{
|
|
||||||
foreach (var child in node.GetChildren())
|
|
||||||
node.RemoveChild(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveAndQueueFreeChildren(this Node node)
|
|
||||||
{
|
|
||||||
foreach (var child in node.GetChildren())
|
|
||||||
{
|
|
||||||
node.RemoveChild(child);
|
|
||||||
child.QueueFree();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void QueueFreeChildren(this Node node)
|
|
||||||
{
|
|
||||||
foreach (var child in node.GetChildren())
|
|
||||||
node.QueueFree();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T? GetAncestor<T>(this Node node) where T : Node
|
|
||||||
{
|
|
||||||
Node current = node;
|
|
||||||
Node root = node.GetTree().Root;
|
|
||||||
while (current != root && !(current is T))
|
|
||||||
current = current.GetParent();
|
|
||||||
|
|
||||||
return current as T;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Node? GetLastChild(this Node node)
|
|
||||||
{
|
|
||||||
var count = node.GetChildCount();
|
|
||||||
if (count == 0) return null;
|
|
||||||
return node.GetChild(count - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T? GetLastChild<T>(this Node node) where T : Node
|
|
||||||
{
|
|
||||||
Node? last = null;
|
|
||||||
foreach (var child in node.GetChildren())
|
|
||||||
{
|
|
||||||
if (child is T) last = child;
|
|
||||||
}
|
|
||||||
|
|
||||||
return last as T;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
<!-- Include Package Assets -->
|
<!-- Include Package Assets -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Ensure package as Source Generator -->
|
<!-- Ensure package as Source Generator -->
|
||||||
|
|
@ -47,5 +47,8 @@
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0"/>
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Generators\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,21 @@ namespace Godot.Sharp.Extended.Generators;
|
||||||
[Generator]
|
[Generator]
|
||||||
public class NodeBindGenerator : IIncrementalGenerator
|
public class NodeBindGenerator : IIncrementalGenerator
|
||||||
{
|
{
|
||||||
|
private const string AttributeSourceCode = """
|
||||||
|
// <auto-generated />
|
||||||
|
namespace Godot.Sharp.Extended.Generators;
|
||||||
|
|
||||||
|
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
|
||||||
|
public class NodeBindAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
""";
|
||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
|
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
|
||||||
|
"NodeBindAttribute.g.cs",
|
||||||
|
SourceText.From(AttributeSourceCode, Encoding.UTF8)));
|
||||||
|
|
||||||
var propertyProvider = context.SyntaxProvider
|
var propertyProvider = context.SyntaxProvider
|
||||||
.CreateSyntaxProvider(
|
.CreateSyntaxProvider(
|
||||||
predicate: (s, _) => s is ClassDeclarationSyntax,
|
predicate: (s, _) => s is ClassDeclarationSyntax,
|
||||||
|
|
@ -47,7 +60,7 @@ public class NodeBindGenerator : IIncrementalGenerator
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var attributeName = symbol.ContainingType.ToDisplayString();
|
var attributeName = symbol.ContainingType.ToDisplayString();
|
||||||
if (attributeName == $"Godot.Sharp.Extended.Attributes.NodeBind")
|
if (attributeName == $"Godot.Sharp.Extended.Generators.NodeBind")
|
||||||
return declarationSyntax;
|
return declarationSyntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,28 @@ namespace Godot.Sharp.Extended.Generators;
|
||||||
[Generator]
|
[Generator]
|
||||||
public class NodePropBindGenerator : IIncrementalGenerator
|
public class NodePropBindGenerator : IIncrementalGenerator
|
||||||
{
|
{
|
||||||
|
private const string AttributeSourceCode = """
|
||||||
|
// <auto-generated/>
|
||||||
|
namespace Godot.Sharp.Extended.Generators;
|
||||||
|
|
||||||
|
[System.AttributeUsage(System.AttributeTargets.Member)]
|
||||||
|
public class NodePropBindAttribute : System.Attribute
|
||||||
|
{
|
||||||
|
public string TargetNodeName { get; private set; }
|
||||||
|
public string GodotPropertyName { get; private set; }
|
||||||
|
|
||||||
|
public NodePropBindAttribute(string targetNodeName, string godotPropertyName)
|
||||||
|
{
|
||||||
|
TargetNodeName = targetNodeName;
|
||||||
|
GodotPropertyName = godotPropertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
|
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
|
||||||
|
"NodePropBind.g.cs",
|
||||||
|
SourceText.From(AttributeSourceCode, Encoding.UTF8)));
|
||||||
|
|
||||||
var propertyProvider = context.SyntaxProvider
|
var propertyProvider = context.SyntaxProvider
|
||||||
.CreateSyntaxProvider(
|
.CreateSyntaxProvider(
|
||||||
|
|
@ -49,7 +69,7 @@ public class NodePropBindGenerator : IIncrementalGenerator
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var attributeName = symbol.ContainingType.ToDisplayString();
|
var attributeName = symbol.ContainingType.ToDisplayString();
|
||||||
if (attributeName == "Godot.Sharp.Extended.Attributes.NodePropBind")
|
if (attributeName == "Godot.Sharp.Extended.Generators.NodePropBind")
|
||||||
return declarationSyntax;
|
return declarationSyntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,11 +132,7 @@ public class NodePropBindGenerator : IIncrementalGenerator
|
||||||
propCode.AppendLine($$"""
|
propCode.AppendLine($$"""
|
||||||
public {{memberDefinition.Type}} {{propName}}
|
public {{memberDefinition.Type}} {{propName}}
|
||||||
{
|
{
|
||||||
get {
|
get => {{memberDefinition.Name}};
|
||||||
if ({{memberDefinition.NodeProp}} == null)
|
|
||||||
return {{memberDefinition.Name}};
|
|
||||||
return {{memberDefinition.NodeProp}}.{{godotProp}};
|
|
||||||
}
|
|
||||||
set {
|
set {
|
||||||
{{memberDefinition.Name}} = value;
|
{{memberDefinition.Name}} = value;
|
||||||
if ({{memberDefinition.NodeProp}} != null)
|
if ({{memberDefinition.NodeProp}} != null)
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,25 @@ namespace Godot.Sharp.Extended.Generators;
|
||||||
[Generator]
|
[Generator]
|
||||||
public class ResourceGenerator : IIncrementalGenerator
|
public class ResourceGenerator : IIncrementalGenerator
|
||||||
{
|
{
|
||||||
|
private const string AttributeSourceCode = """
|
||||||
|
// <auto-generated />
|
||||||
|
namespace Godot.Sharp.Extended.Generators;
|
||||||
|
|
||||||
|
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
|
||||||
|
public class ResourcePathAttribute : System.Attribute
|
||||||
|
{
|
||||||
|
public string Path { get; private set; }
|
||||||
|
|
||||||
|
public ResourcePathAttribute(string path) {
|
||||||
|
Path = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
|
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
|
||||||
|
"ResourcePathAttribute.g.cs",
|
||||||
|
SourceText.From(AttributeSourceCode, Encoding.UTF8)));
|
||||||
|
|
||||||
var classPaths = context.SyntaxProvider
|
var classPaths = context.SyntaxProvider
|
||||||
.CreateSyntaxProvider(
|
.CreateSyntaxProvider(
|
||||||
|
|
@ -65,7 +82,7 @@ public class ResourceGenerator : IIncrementalGenerator
|
||||||
{
|
{
|
||||||
var symbolInfo = ctx.SemanticModel.GetSymbolInfo(attributeSyntax);
|
var symbolInfo = ctx.SemanticModel.GetSymbolInfo(attributeSyntax);
|
||||||
if (symbolInfo.Symbol is not IMethodSymbol attributeSymbol) continue;
|
if (symbolInfo.Symbol is not IMethodSymbol attributeSymbol) continue;
|
||||||
if (attributeSymbol.ContainingType.ToDisplayString() != "Godot.Sharp.Extended.Attributes.ResourcePath") continue;
|
if (attributeSymbol.ContainingType.ToDisplayString() != "Godot.Sharp.Extended.Generators.ResourcePath") continue;
|
||||||
var parameter = attributeSyntax.ArgumentList;
|
var parameter = attributeSyntax.ArgumentList;
|
||||||
var pathArgument = parameter?.Arguments[0];
|
var pathArgument = parameter?.Arguments[0];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.5.2.0
|
VisualStudioVersion = 17.5.2.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.Sharp.Extended.Generators", "Generators\\Godot.Sharp.Extended.Generators.csproj", "{4D64B952-274C-14C1-D766-218DC5756B49}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.Sharp.Extended", "Godot.Sharp.Extended.csproj", "{4D64B952-274C-14C1-D766-218DC5756B49}"
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.Sharp.Extended", "Core\Godot.Sharp.Extended.csproj", "{0953FAF6-8FA7-41C8-BE4E-08ADECADB518}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
@ -16,10 +14,6 @@ Global
|
||||||
{4D64B952-274C-14C1-D766-218DC5756B49}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4D64B952-274C-14C1-D766-218DC5756B49}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4D64B952-274C-14C1-D766-218DC5756B49}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4D64B952-274C-14C1-D766-218DC5756B49}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4D64B952-274C-14C1-D766-218DC5756B49}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4D64B952-274C-14C1-D766-218DC5756B49}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{0953FAF6-8FA7-41C8-BE4E-08ADECADB518}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{0953FAF6-8FA7-41C8-BE4E-08ADECADB518}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{0953FAF6-8FA7-41C8-BE4E-08ADECADB518}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{0953FAF6-8FA7-41C8-BE4E-08ADECADB518}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue