derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
679 stars 33 forks source link

feat: connect state signals to C# events using Callable.From #126

Closed Prakkkmak closed 5 days ago

Prakkkmak commented 3 weeks ago

This merge request introduces the ability to connect Godot state signals to C# events using Callable.From, providing a more idiomatic way to handle signals in C#.

Changes:

Motivation: Connecting signals using Callable.From aligns with the recommended practices for handling signals in Godot using C#. This change improves type safety and readability of the code.

~ Co Created With Chat GPT

derkork commented 3 weeks ago

Thank you very much for submitting this PR! While I agree on the intention of this, I think this approach has a few drawbacks.

I think a better approach would be to provide a type-safe Connect variant. I have created a branch lining out the idea (check https://github.com/derkork/godot-statecharts/compare/main...csharp-type-safe-signals). I think the external API is quite nice, you can do a:


my_state.StateEntered.Connect(OnStateEntered);

// ... 

void OnStateEntered() {
}

though internally it's a lot to write in the wrapper classes. Then again, it's a one and done.

Prakkkmak commented 3 weeks ago

I followed the guideline of += and -= of the documentation to keep consistency:

https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_signals.html

I would use your approach eventually in future updates.