LokiCat.GodotNodeInterfaces.Observables 1.0.23

dotnet add package LokiCat.GodotNodeInterfaces.Observables --version 1.0.23
                    
NuGet\Install-Package LokiCat.GodotNodeInterfaces.Observables -Version 1.0.23
                    
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="LokiCat.GodotNodeInterfaces.Observables" Version="1.0.23" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LokiCat.GodotNodeInterfaces.Observables" Version="1.0.23" />
                    
Directory.Packages.props
<PackageReference Include="LokiCat.GodotNodeInterfaces.Observables" />
                    
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 LokiCat.GodotNodeInterfaces.Observables --version 1.0.23
                    
#r "nuget: LokiCat.GodotNodeInterfaces.Observables, 1.0.23"
                    
#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 LokiCat.GodotNodeInterfaces.Observables@1.0.23
                    
#: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=LokiCat.GodotNodeInterfaces.Observables&version=1.0.23
                    
Install as a Cake Addin
#tool nuget:?package=LokiCat.GodotNodeInterfaces.Observables&version=1.0.23
                    
Install as a Cake Tool

LokiCat.GodotNodeInterfaces.Observables

Generate R3 Observables from Godot signals via Chickensoft.GodotNodeInterfaces

NuGet CI


Overview

Why bother?

We want:

  1. ✅ To program to interfaces (via Chickensoft.GodotNodeInterfaces)
  2. ✅ To use ReactiveX-style observables (via R3)
  3. ❌ But we don't want to manually wire every Godot signal ourselves

This library gives us declarative, strongly-typed observables for signals across interfaces, Godot built-ins, and [Signal] delegates — all auto-generated.

Baseline: Manual event wiring
public partial class MyMenu : Control, IControl {
  private IBaseButton button;

  public void OnReady() {
    button.Pressed += HandlePressed;
  }

  public void OnExitTree() {
    button.Pressed -= HandlePressed;
  }

  private void HandlePressed() => GD.Print("Pressed!");
}
  • ❌ Must manage subscribe/unsubscribe manually
  • ❌ Can’t compose with R3
Manual R3 Observable
Observable.FromEvent<PressedEventHandler, Unit>(
  h => () => h(Unit.Default),
  h => button.Pressed += h,
  h => button.Pressed -= h
)
.Subscribe(_ => GD.Print("Pressed"))
.AddTo(this);
  • ✅ Works
  • ❌ Verbose
  • ❌ Easy to miswire
✅ With LokiCat.GodotNodeInterfaces.Observables
button.OnPressedAsObservable()
  .Subscribe(_ => GD.Print("Pressed"))
  .AddTo(this);
  • ✅ Clean
  • ✅ Reactive
  • ✅ Auto cleanup
  • ✅ Interface- and class-based support
  • ✅ Works for custom [Signal]s and built-ins

This project provides Roslyn source generators that create R3 observables for:

  1. All events defined in Chickensoft.GodotNodeInterfaces interfaces.
  2. All signals in built-in Godot classes (e.g., Button, Node2D) if you define a partial class in your project.
  3. Any user-defined [Signal] delegate in your own Godot partial classes.

These generators output strongly-typed, composable observables for signals using idiomatic R3 patterns.

Why use this?

  • ✅ Program to interfaces with Chickensoft.GodotNodeInterfaces
  • ✅ Use ReactiveX (R3) for signal handling
  • ✅ Avoid writing manual signal-to-observable plumbing
  • ✅ Get compile-time safety and auto-cleanup via .AddTo(this)

🔍 Example

public partial class MyMenu : Control, IControl {
  private IBaseButton doSomethingButton;

  public override void _Ready() {
    doSomethingButton.OnPressedAsObservable()
      .Subscribe(_ => GD.Print("Pressed!"))
      .AddTo(this);
  }
}

If you define your own [Signal]-annotated delegates:

[Signal] private delegate void ToggledEventHandler(bool toggled);

public partial class ToggleThing : Node {
  private Subject<bool> _onToggled = new();
  public Observable<bool> OnToggled => _onToggled ??= ConnectToggled();
}

And for built-in classes:

public partial class Button : Godot.Button { }

Triggers generation of:

private Subject<Unit>? _onPressed;
public Observable<Unit> OnPressed => _onPressed ??= ConnectPressed();

✨ Features

  • 🔧 Zero config — just mark your classes partial and you're done
  • ⚙️ Supports 0–5 signal parameters
  • 📡 Built-in Godot signal support via known interface mappings
  • 🧠 Handles custom signal delegates with or without constructors
  • 📎 Avoids duplicating built-in signal wiring
  • 🧪 Thoroughly tested with diagnostic output

📦 Installation

Install via NuGet:

dotnet add package LokiCat.GodotNodeInterfaces.Observables

🧪 Tests

Covers:

  • Signals with 0–5 parameters
  • Interfaces with custom and standard delegate types
  • Edge cases like non-partial classes or invalid delegate wiring
dotnet test

🧱 How It Works

  • Scans Chickensoft.GodotNodeInterfaces for all interfaces with events.

  • For each:

    • Emits extension method On[EventName]AsObservable()
  • Separately, scans all partial classes in your project:

    • If it inherits a known Godot class (e.g., Button), emits _onX / OnX fields + observable logic for signals like pressed, toggled, etc.
    • If it defines a [Signal]-annotated delegate, generates a subject-backed observable for it.
  • Supports 0–5 parameters; skips and warns if more.


🙏 Credits


📄 License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.23 147 5/10/2025
1.0.22 376 4/19/2025
1.0.21 185 4/19/2025
1.0.20 169 4/19/2025
1.0.19 111 4/19/2025
1.0.18 114 4/19/2025
1.0.17 208 4/15/2025
1.0.16 213 4/15/2025
1.0.15 218 4/13/2025
1.0.14 200 4/13/2025
1.0.13 197 4/13/2025