diff --git a/Core/Attributes/NodeBindAttribute.cs b/Core/Attributes/NodeBindAttribute.cs
new file mode 100644
index 0000000..5970653
--- /dev/null
+++ b/Core/Attributes/NodeBindAttribute.cs
@@ -0,0 +1,6 @@
+namespace Godot.Sharp.Extended.Attributes;
+
+[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
+public class NodeBindAttribute : Attribute
+{
+}
\ No newline at end of file
diff --git a/Core/Attributes/NodeBindPropAttribute.cs b/Core/Attributes/NodeBindPropAttribute.cs
new file mode 100644
index 0000000..c215cce
--- /dev/null
+++ b/Core/Attributes/NodeBindPropAttribute.cs
@@ -0,0 +1,14 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/Core/Attributes/ResourcePathAttribute.cs b/Core/Attributes/ResourcePathAttribute.cs
new file mode 100644
index 0000000..347dc67
--- /dev/null
+++ b/Core/Attributes/ResourcePathAttribute.cs
@@ -0,0 +1,11 @@
+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;
+ }
+}
\ No newline at end of file
diff --git a/Core/Godot.Sharp.Extended.csproj b/Core/Godot.Sharp.Extended.csproj
new file mode 100644
index 0000000..29df43d
--- /dev/null
+++ b/Core/Godot.Sharp.Extended.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net8.0
+ enable
+ enable
+ Godot.Sharp.Extended
+
+
+
+
+
+
+
diff --git a/Core/Tools/MathFunctionExtensions.cs b/Core/Tools/MathFunctionExtensions.cs
new file mode 100644
index 0000000..9fd8cf4
--- /dev/null
+++ b/Core/Tools/MathFunctionExtensions.cs
@@ -0,0 +1,22 @@
+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);
+}
\ No newline at end of file
diff --git a/Core/Tools/NodeExtensions.cs b/Core/Tools/NodeExtensions.cs
new file mode 100644
index 0000000..4ede49d
--- /dev/null
+++ b/Core/Tools/NodeExtensions.cs
@@ -0,0 +1,65 @@
+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(this Node node) where T : Node => node.GetNode(typeof(T).Name);
+ public static Array GetChildrenOfType(this Node node) where T : Node
+ {
+ var children = node.GetChildren();
+
+ return new Array(children.OfType().ToArray());
+ }
+ public static T? GetFirstChildOfType(this Node node) where T : Node => GetChildrenOfType(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(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(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;
+ }
+}
\ No newline at end of file
diff --git a/Generators/Godot.Sharp.Extended.Generators.csproj b/Generators/Godot.Sharp.Extended.Generators.csproj
index 76a778e..69db88d 100644
--- a/Generators/Godot.Sharp.Extended.Generators.csproj
+++ b/Generators/Godot.Sharp.Extended.Generators.csproj
@@ -31,7 +31,7 @@
-
+
@@ -47,8 +47,5 @@
-
-
-
diff --git a/Generators/NodeBindGenerator.cs b/Generators/NodeBindGenerator.cs
index 89a7c58..8c8a9f6 100644
--- a/Generators/NodeBindGenerator.cs
+++ b/Generators/NodeBindGenerator.cs
@@ -12,21 +12,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
public class NodeBindGenerator : IIncrementalGenerator
{
- private const string AttributeSourceCode = """
- //
- namespace Godot.Sharp.Extended.Generators;
-
- [System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
- public class NodeBindAttribute : Attribute
- {
- }
- """;
public void Initialize(IncrementalGeneratorInitializationContext context)
{
- context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
- "NodeBindAttribute.g.cs",
- SourceText.From(AttributeSourceCode, Encoding.UTF8)));
-
var propertyProvider = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: (s, _) => s is ClassDeclarationSyntax,
@@ -60,7 +47,7 @@ public class NodeBindGenerator : IIncrementalGenerator
continue;
var attributeName = symbol.ContainingType.ToDisplayString();
- if (attributeName == $"Godot.Sharp.Extended.Generators.NodeBind")
+ if (attributeName == $"Godot.Sharp.Extended.Attributes.NodeBind")
return declarationSyntax;
}
diff --git a/Generators/NodePropBindGenerator.cs b/Generators/NodePropBindGenerator.cs
index 681f9cb..603cb98 100644
--- a/Generators/NodePropBindGenerator.cs
+++ b/Generators/NodePropBindGenerator.cs
@@ -13,28 +13,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
public class NodePropBindGenerator : IIncrementalGenerator
{
- private const string AttributeSourceCode = """
- //
- 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)
{
- context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
- "NodePropBind.g.cs",
- SourceText.From(AttributeSourceCode, Encoding.UTF8)));
var propertyProvider = context.SyntaxProvider
.CreateSyntaxProvider(
@@ -69,7 +49,7 @@ public class NodePropBindGenerator : IIncrementalGenerator
continue;
var attributeName = symbol.ContainingType.ToDisplayString();
- if (attributeName == "Godot.Sharp.Extended.Generators.NodePropBind")
+ if (attributeName == "Godot.Sharp.Extended.Attributes.NodePropBind")
return declarationSyntax;
}
@@ -132,7 +112,11 @@ public class NodePropBindGenerator : IIncrementalGenerator
propCode.AppendLine($$"""
public {{memberDefinition.Type}} {{propName}}
{
- get => {{memberDefinition.Name}};
+ get {
+ if ({{memberDefinition.NodeProp}} == null)
+ return {{memberDefinition.Name}};
+ return {{memberDefinition.NodeProp}}.{{godotProp}};
+ }
set {
{{memberDefinition.Name}} = value;
if ({{memberDefinition.NodeProp}} != null)
diff --git a/Generators/ResourceGenerator.cs b/Generators/ResourceGenerator.cs
index 1a458f1..a612221 100644
--- a/Generators/ResourceGenerator.cs
+++ b/Generators/ResourceGenerator.cs
@@ -14,25 +14,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
public class ResourceGenerator : IIncrementalGenerator
{
- private const string AttributeSourceCode = """
- //
- 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)
{
- context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
- "ResourcePathAttribute.g.cs",
- SourceText.From(AttributeSourceCode, Encoding.UTF8)));
var classPaths = context.SyntaxProvider
.CreateSyntaxProvider(
@@ -82,7 +65,7 @@ public class ResourceGenerator : IIncrementalGenerator
{
var symbolInfo = ctx.SemanticModel.GetSymbolInfo(attributeSyntax);
if (symbolInfo.Symbol is not IMethodSymbol attributeSymbol) continue;
- if (attributeSymbol.ContainingType.ToDisplayString() != "Godot.Sharp.Extended.Generators.ResourcePath") continue;
+ if (attributeSymbol.ContainingType.ToDisplayString() != "Godot.Sharp.Extended.Attributes.ResourcePath") continue;
var parameter = attributeSyntax.ArgumentList;
var pathArgument = parameter?.Arguments[0];
diff --git a/Godot.Sharp.Extended.sln b/Godot.Sharp.Extended.sln
index 4ba4e2c..6d17c3d 100644
--- a/Godot.Sharp.Extended.sln
+++ b/Godot.Sharp.Extended.sln
@@ -2,7 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.Sharp.Extended", "Godot.Sharp.Extended.csproj", "{4D64B952-274C-14C1-D766-218DC5756B49}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Godot.Sharp.Extended.Generators", "Generators\\Godot.Sharp.Extended.Generators.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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -14,6 +16,10 @@ Global
{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.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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE