Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
feat: allow PowerUps to be applied to any class extending GodotObject (
Browse files Browse the repository at this point in the history
…#13)

* feat: allow PowerUps to be applied to any class extending GodotObject

* chore: bump version
  • Loading branch information
jolexxa authored Sep 17, 2023
1 parent af0cfb6 commit 83fc7b9
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"console": "internalConsole",
"stopAtEntry": false
},
// For these launch configurations to work, you need to setup a GODOT4
// For these launch configurations to work, you need to setup a GODOT
// environment variable. On mac or linux, this can be done by adding
// the following to your .zshrc, .bashrc, or .bash_profile file:
// export GODOT4="/Applications/Godot.app/Contents/MacOS/Godot"
Expand All @@ -26,7 +26,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-testcases",
"program": "${env:GODOT4}",
"program": "${env:GODOT}",
"args": [
// These command line flags are used by GoDotTest to run tests.
"--run-tests",
Expand All @@ -40,7 +40,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-testcases",
"program": "${env:GODOT4}",
"program": "${env:GODOT}",
"args": [
// These command line flags are used by GoDotTest to run tests.
"--run-tests=${fileBasenameNoExtension}",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SuperNodes is a C# source generator that gives superpowers to Godot node scripts

SuperNodes can do a LOT — [check out the official documentation][docs] for usage details.

- ✅ Apply PowerUps (essentially mixins for C#) to your node scripts.
- ✅ Apply PowerUps (essentially mixins for C#) to any class that extends a Godot `Node` or `GodotObject`.
- ✅ Use third-party source generators alongside Godot's official source generators.
- ✅ Get and set the value of script properties and fields at runtime, without using reflection.
- ✅ Examine the attributes and types of script properties and fields at runtime, without using reflection.
Expand Down
12 changes: 12 additions & 0 deletions SuperNodes.TestCases/test/test_cases/SuperGodotObjectTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SuperGodotObject;

using Godot;
using SuperNodes.Types;

[SuperNode(typeof(MyPowerUp))]
public partial class SuperGodotObject : GodotObject {
public override partial void _Notification(int what);
}

[PowerUp]
public partial class MyPowerUp : GodotObject { }
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void GeneratesPowerUp() {
var code = """
[PowerUp]
public partial class TestPowerUp<TA, TB>
: Godot.Node, ITestPowerUp<TA, TB> {
: Godot.Object, ITestPowerUp<TA, TB> {
public static ScriptPropertyOrField[] ScriptPropertiesAndFields { get; }
= default!;
public TResult GetScriptPropertyOrFieldType<TResult>(
Expand Down Expand Up @@ -62,7 +62,7 @@ public void OnTestPowerUp(int what) {
Name: "TestPowerUp",
FullName: "global::Tests.TestPowerUp",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: new string[] { "TA", "TB" }.ToImmutableArray(),
Interfaces: new string[] {
"global::Tests.ITestPowerUp<TA, TB>"
Expand All @@ -87,7 +87,7 @@ public void OnTestPowerUp(int what) {
Name: "TestSuperNode",
NameWithoutGenerics: "TestSuperNode",
Location: new Mock<Location>().Object,
BaseClasses: new string[] { "global::Godot.Node" }.ToImmutableArray(),
BaseClasses: new string[] { "global::Godot.Object" }.ToImmutableArray(),
LifecycleHooks: ImmutableArray<IGodotNodeLifecycleHook>.Empty,
PowerUpHooksByFullName: powerUpHooksByFullName,
NotificationHandlers: ImmutableArray<string>.Empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class SuperNodeGeneratorServiceTest {
Name: "TestPowerUp",
FullName: "global::TestPowerUp",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: new string[] { "TA", "TB" }.ToImmutableArray(),
Interfaces: ImmutableArray<string>.Empty,
Source: "[PowerUp] public class TestPowerUp {}",
Expand Down Expand Up @@ -177,7 +177,7 @@ public void GeneratesLifecycleInvocations() {
Name: "TestPowerUp",
FullName: "global::TestPowerUp",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: ImmutableArray<string>.Empty,
Interfaces: ImmutableArray<string>.Empty,
Source: "[PowerUp] public class TestPowerUp {}",
Expand All @@ -190,7 +190,7 @@ public void GeneratesLifecycleInvocations() {
Name: "TestPowerUp2",
FullName: "global::TestPowerUp2",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: ImmutableArray<string>.Empty,
Interfaces: ImmutableArray<string>.Empty,
Source: "[PowerUp] public class TestPowerUp2 {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void GeneratesSuperNode() {
Name: "TestSuperNode",
NameWithoutGenerics: "TestSuperNode",
Location: new Mock<Location>().Object,
BaseClasses: new string[] { "global::Godot.Node" }.ToImmutableArray(),
BaseClasses: new string[] { "global::Godot.Object" }.ToImmutableArray(),
LifecycleHooks: lifecycleHooks,
PowerUpHooksByFullName: ImmutableDictionary<string, PowerUpHook>.Empty,
NotificationHandlers: notificationHandlers,
Expand Down Expand Up @@ -158,7 +158,7 @@ public void GeneratesSuperNodeStaticReflectionTables() {
Name: "TestPowerUp",
FullName: "global::TestPowerUp",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: ImmutableArray<string>.Empty,
Interfaces: ImmutableArray<string>.Empty,
Source: "[PowerUp] public class TestPowerUp {}",
Expand Down Expand Up @@ -187,7 +187,7 @@ public void GeneratesSuperNodeStaticReflectionTables() {
Name: "TestSuperNode",
NameWithoutGenerics: "TestSuperNode",
Location: new Mock<Location>().Object,
BaseClasses: new string[] { "global::Godot.Node" }.ToImmutableArray(),
BaseClasses: new string[] { "global::Godot.Object" }.ToImmutableArray(),
LifecycleHooks: ImmutableArray<IGodotNodeLifecycleHook>.Empty,
PowerUpHooksByFullName: powerUpHooksByFullName,
NotificationHandlers: ImmutableArray<string>.Empty,
Expand Down
2 changes: 1 addition & 1 deletion SuperNodes.Tests/tests/common/models/GenerationItemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Initializes() {
Name: "SuperNode",
NameWithoutGenerics: "SuperNode",
Location: new Mock<Location>().Object,
BaseClasses: new string[] { "global::Godot.Node" }.ToImmutableArray(),
BaseClasses: new string[] { "global::Godot.Object" }.ToImmutableArray(),
LifecycleHooks: ImmutableArray<IGodotNodeLifecycleHook>.Empty,
PowerUpHooksByFullName: ImmutableDictionary<string, PowerUpHook>.Empty,
NotificationHandlers: ImmutableArray<string>.Empty,
Expand Down
4 changes: 2 additions & 2 deletions SuperNodes.Tests/tests/common/models/PowerUpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Initializes() {
Name: "PowerUp",
FullName: "global::Tests.PowerUp",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: ImmutableArray<string>.Empty,
Interfaces: ImmutableArray<string>.Empty,
Source: "namespace Tests { [PowerUp] public class PowerUp {} }",
Expand All @@ -34,7 +34,7 @@ public void IsGenericRecognizes() {
Name: "PowerUp",
FullName: "global::Tests.PowerUp",
Location: new Mock<Location>().Object,
BaseClass: "global::Godot.Node",
BaseClass: "global::Godot.Object",
TypeParameters: ImmutableArray.Create("T"),
Interfaces: ImmutableArray<string>.Empty,
Source: "namespace Tests { [PowerUp] public class PowerUp<T> {} }",
Expand Down
4 changes: 2 additions & 2 deletions SuperNodes.Tests/tests/common/models/SuperNodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Initializes() {
Name: "SuperNode",
NameWithoutGenerics: "SuperNode",
Location: new Mock<Location>().Object,
BaseClasses: new string[] { "global::Godot.Node" }.ToImmutableArray(),
BaseClasses: new string[] { "global::Godot.Object" }.ToImmutableArray(),
LifecycleHooks: ImmutableArray<IGodotNodeLifecycleHook>.Empty,
PowerUpHooksByFullName: ImmutableDictionary<string, PowerUpHook>.Empty,
NotificationHandlers: ImmutableArray<string>.Empty,
Expand All @@ -36,7 +36,7 @@ public void FilenamePrefixHandlesEmptyNamespace() {
Name: "SuperNode",
NameWithoutGenerics: "SuperNode",
Location: new Mock<Location>().Object,
BaseClasses: new string[] { "global::Godot.Node" }.ToImmutableArray(),
BaseClasses: new string[] { "global::Godot.Object" }.ToImmutableArray(),
LifecycleHooks: ImmutableArray<IGodotNodeLifecycleHook>.Empty,
PowerUpHooksByFullName: ImmutableDictionary<string, PowerUpHook>.Empty,
NotificationHandlers: ImmutableArray<string>.Empty,
Expand Down
2 changes: 1 addition & 1 deletion SuperNodes.Types/Chickensoft.SuperNodes.Types.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<DebugType>portable</DebugType>

<Title>SuperNodes Types</Title>
<Version>1.5.1</Version>
<Version>1.6.0</Version>
<Description>Runtime types for SuperNodes.</Description>
<Copyright>© 2023 Chickensoft</Copyright>
<Authors>Chickensoft</Authors>
Expand Down
8 changes: 4 additions & 4 deletions SuperNodes.Types/src/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SuperNodes.Types;
using Godot;

/// <summary>
/// SuperNode attribute. Add this to a Godot node script class to use
/// SuperNode attribute. Add this to a Godot object class to use
/// functionality from other compatible source generators.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
Expand All @@ -18,15 +18,15 @@ public sealed class SuperNodeAttribute : Attribute {
public object[] Args { get; }

/// <summary>
/// SuperNode attribute. Add this to a Godot node script class to use
/// SuperNode attribute. Add this to a Godot object class to use
/// functionality from other compatible source generators.
/// </summary>
public SuperNodeAttribute() {
Args = Array.Empty<object>();
}

/// <summary>
/// SuperNode attribute. Add this to a Godot node script class to use
/// SuperNode attribute. Add this to a Godot object class to use
/// functionality from other compatible source generators.
/// <br />
/// Compatible source generator lifecycle methods or PowerUps that will
Expand Down Expand Up @@ -183,7 +183,7 @@ public static class NodeExtensions {
/// name (e.g. System.Int32 instead of int). For best results, use the
/// simpler type names wherever possible.
/// </summary>
/// <param name="node">Godot node.</param>
/// <param name="node">Godot object.</param>
/// <param name = "type">Type whose name should be computed.</param>
/// <exception cref = "InvalidOperationException">Thrown if an unrecognized
/// primitive type is encountered.</exception>
Expand Down
2 changes: 1 addition & 1 deletion SuperNodes/Chickensoft.SuperNodes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<NoWarn>NU5128</NoWarn>

<Title>SuperNodes</Title>
<Version>1.5.1</Version>
<Version>1.6.0</Version>
<Description>Supercharge your Godot nodes with lifecycle-aware mixins, third party source generators, script introspection, and dynamic property manipulation — all without runtime reflection!</Description>
<Copyright>© 2023 Chickensoft Games</Copyright>
<Authors>Chickensoft</Authors>
Expand Down
4 changes: 2 additions & 2 deletions SuperNodes/src/common/utils/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Constants {
/// <summary>Spaces per tab. Adjust to your generator's liking.</summary>
public static int SPACES_PER_INDENT = 2;

public const string DEFAULT_BASE_CLASS = "global::Godot.Node";
public const string DEFAULT_BASE_CLASS = "global::Godot.Object";

public static string BaseClass { get; set; } = DEFAULT_BASE_CLASS;

Expand Down Expand Up @@ -44,7 +44,7 @@ public static readonly Dictionary<string, LifecycleMethod>
["OnPredelete"] = new LifecycleMethod(
"NotificationPredelete", VOID, NoArgs
),
// Godot.Node Notifications
// Godot.Object Notifications
["OnEnterTree"] = new LifecycleMethod(
"NotificationEnterTree", VOID, NoArgs
),
Expand Down

0 comments on commit 83fc7b9

Please sign in to comment.