-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-opening: Proper Godot Signal Support #288
base: main
Are you sure you want to change the base?
Re-opening: Proper Godot Signal Support #288
Conversation
Reason for re-openingWell, first, seems like few people saw my previous PR (I myself forgot it) :p After using R3 for about 2 months, I came to the belief that this is still worth it. Signals allow cross-language programming with GDScript, and relying solely on Rx (even C#) is like throwing away lots of the flexibility that Godot provides. Besides, many of Godot's engine features are exposed as signals. And yes I'm aware that my original implementation was premature and actually quite dirty. So I rewrote it almost entirely, utilizing existing R3 facilities as much as I could. So please take a look. Below is edited from the original PR: SummaryExtension methods and utility classes for easy conversion from Godot signal to observable or MotivationAlthough we can use var observable = Observable.FromEvent<WhoType>(
h => myCheese.Touched += h,
h => myCheese.Touched -= h
); It:
Prefer this: var observable = myCheese.SignalAsObservable<WhoType>(Cheese.SignalName.Touched);
Additionally, support var observable = myCheese.SignalAsObservable<WhoType>(Cheese.SignalName.Touched, funnyToken); If no token is provided (or "funnyToken" is actually For convenience, I also provide a var funnyToken = this.CancelOnSignal(Node.SignalName.Ready); // cancels when this `Node` emits `Ready` which can also be used with public override void _Ready()
{
base._Ready();
// one-statement signal wiring:
Disposable.Combine(
_game.ScoreObservable
.Subscribe(this, (score, self) => self.ScoreLabel.Text = score.ToString()),
_game.SignalAsObservable(Game.SignalName.GameOver)
.Subscribe(this, (_, self) => self.DisplayGameOverBanner()),
// ... lots of subscriptions
).RegisterTo(HudRoot.CancelOnSignal(Node.SignalName.TreeExited)); // easy cancellation on any signal
} |
Re-opening of #199 in the belief it'll help people :)