Firebelley.GodotUtilities.SourceGenerators 5.0.0

dotnet add package Firebelley.GodotUtilities.SourceGenerators --version 5.0.0
                    
NuGet\Install-Package Firebelley.GodotUtilities.SourceGenerators -Version 5.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Firebelley.GodotUtilities.SourceGenerators" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Firebelley.GodotUtilities.SourceGenerators" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Firebelley.GodotUtilities.SourceGenerators" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Firebelley.GodotUtilities.SourceGenerators --version 5.0.0
                    
#r "nuget: Firebelley.GodotUtilities.SourceGenerators, 5.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Firebelley.GodotUtilities.SourceGenerators@5.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Firebelley.GodotUtilities.SourceGenerators&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Firebelley.GodotUtilities.SourceGenerators&version=5.0.0
                    
Install as a Cake Tool

GodotUtilities

Usage

Built for Godot 4. Use versions ⇐ 2 for Godot 3 compatibility.

Add Firebelley.GodotUtilities to your .csproj: https://www.nuget.org/packages/Firebelley.GodotUtilities/#readme-body-tab

Source Generation

You may find it unwieldy in C# to constantly be assigning member variables to nodes using GetNode. Consider:

using Godot;

public partial class MyClass : Node {
    private Label label;
    private Sprite2D sprite2d;
    private AudioStreamPlayer audioStreamPlayer;
    
    public override void _Ready() {
        label = GetNodeOrNull<Label>("Label");
        sprite2d = GetNodeOrNull<Sprite2D>("Sprite2D");
        // and on...
    }
}

This is a lot of boilerplate to write. This repository includes a source generator to reduce this boilerplate, based on this repository. Be sure to check out that repository for a more sophisticated set of generators.

With the included source generator, you can now write this code like so with the [Scene] and [Node] attributes:

using Godot;
using GodotUtilities;

[Scene]
public partial class MyClass : Node {
    [Node]
    private Label label;
    [Node]
    private Sprite2D sprite2d;
    [Node("Some/Nested/AudioStreamPlayer")] // a node path can optionally be supplied
    private AudioStreamPlayer audioStreamPlayer;
    
    public override void _Notification(int what) {
        if (what == NotificationSceneInstantiated) {
            WireNodes(); // this is a generated method
        }
    }
}

I recommend using the NotificationSceneInstantiated notification because this will make your node assignments available immediately upon instantiating a scene. However, you can call WireNodes whenever you want. Be aware that nodes will not be assigned until this method is called.

Nodes are matched using the following rules. The first match is assigned to the member.

  1. Get a node at the node path if supplied in the [Node] attribute
  2. Get a direct child with PascalCase member name: GetNodeOrNull<Label>("MyLabel")
  3. Get a unique descendant with PascalCase member name: GetNodeOrNull<Label>("%MyLabel")
  4. Get a direct child with snake_case member name: GetNodeOrNull<Label>("my_label")
  5. Get a unique descendant with snake_case member name: GetNodeOrNull<Label>("%my_label)
  6. Get a direct child with camelCase member name: GetNodeOrNull<Label>("myLabel")
  7. Get a unique descendant with camelCase member name: GetNodeOrNull<Label>("%myLabel)
  8. Get a direct child with member name converted to lower case: GetNodeOrNull<Label>("mylabel")
  9. Get a unique descendant with member name converted to lower case: GetNodeOrNull<Label>("%mylabel")

An error will be printed in the console if nothing was matched.

Delegate State Machine

There is a DelegateStateMachine which is a simple finite state machine that can be used like so:

using GodotUtilities.Logic;

private DelegateStateMachine stateMachine = new DelegateStateMachine();

public override void _Ready() {
    stateMachine.AddStates(StateNormal, EnterStateNormal, LeaveStateNormal);
    stateMachine.AddStates(StateFlee);
    stateMachine.AddStates(StateAttack, null, LeaveStateAttack);
    stateMachine.SetInitialState(StateNormal); // important. The initial state will have its enter function called
}

public override void _Process(double delta) {
    stateMachine.Update(); // triggers an update of the current state and calls enter and leave states as necessary
}

private void EnterStateNormal() {
    // called when normal state is entered
}

private void StateNormal() {
    // frame-by-frame state logic here
    // when you want to change states:
    stateMachine.ChangeState(StateAttack);
}

private void LeaveStateNormal() {
    // called when normal state is left
}

// so on...

Extensions

There are various extensions available to make your development experience more streamlined. Take a look through the source code to get an idea of what is available to you.

A Note on Versioning

This project follows semantic versioning. All minor and patch version upgrades will be safe to use in your project. Major version upgrades will contain breaking API changes.

If you're using version 3.x, then any future 3.x version will be backward compatible with your project.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Firebelley.GodotUtilities.SourceGenerators:

Package Downloads
Firebelley.GodotUtilities

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0 1,794 4/7/2024
4.1.2 649 10/4/2023
4.1.0 389 7/7/2023
4.0.4 282 6/2/2023
4.0.3 273 5/29/2023
4.0.2 319 4/27/2023
4.0.1 284 4/25/2023