Compare commits

...

4 commits

Author SHA1 Message Date
1ee021029b Finished restructure
Ensured all things are properly named, finalizing the restructure.
2025-09-26 20:15:34 -05:00
d96fbaf0e9 Updated Generators
Removed un-nesscary Attribute generation, as now is part of core.
2025-09-26 20:15:14 -05:00
02d23935fa Updated CSProj
Removed Empty Generators Folder Include
Changed README.md location.
2025-09-26 20:13:10 -05:00
b4a2ce40c1 Added Core Functionality
Added core functionality that was from the old Godot.Sharp.Extra library.  Not all functions, only functions that were considered worth porting.
2025-09-26 20:12:37 -05:00
11 changed files with 148 additions and 59 deletions

View file

@ -0,0 +1,6 @@
namespace Godot.Sharp.Extended.Attributes;
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
public class NodeBindAttribute : Attribute
{
}

View file

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

View file

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

View file

@ -0,0 +1,14 @@
<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>

View file

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

View file

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

View file

@ -31,7 +31,7 @@
<!-- Include Package Assets -->
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<!-- Ensure package as Source Generator -->
@ -47,8 +47,5 @@
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Generators\" />
</ItemGroup>
</Project>

View file

@ -12,21 +12,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
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)
{
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;
}

View file

@ -13,28 +13,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
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)
{
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)

View file

@ -14,25 +14,8 @@ namespace Godot.Sharp.Extended.Generators;
[Generator]
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)
{
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];

View file

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