You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
223: Object notification API, `engine` intra-doc links r=Bromeon a=Bromeon
So far, there was no way to intercept the Godot `_notification` API, and also issuing notifications was very cumbersome, as the constants were spread across several classes.
This PR introduces multiple new APIs:
1. `{Class}Notification` enum, which contains all notifications relevant for a given class.
* For example, `Node3DNotification` accumulates all `NOTIFICATION_*` constants across `Node3D`, `Node` and `Object` classes.
* In GDScript, this is less of an issue because there is true inheritance, so one can type `Node3D.NOTIF...` and auto-complete will list all candidates. In Rust, constants are not inherited.
* There is currently a workaround for bug [godot#75839](godotengine/godot#75839): in two cases, two enumerators cannot be distinguished as they share the same integer value. We address this by using a single enumerator to represent both (not ideal, but there's nothing else we can do).
2. Virtual method `{Class}Virtual::on_notification(what: {NearestClass}Notification)`.
* This is the equivalent to GDScript's `_notification` (with underscore), but more meaningfully named. It can be used to intercept low-level notifications for the given class.
* The parameter type is either the notification enum for that class; or if the class itself does not have any notification constants, the nearest base class that _does_. This avoids proliferation of enum types with the exact same interface. It's possibly breaking when Godot adds such constants in new classes, but it helps reduce the API surface if not _every single class_ needs its own enum (since there are relatively few classes working with notifications).
3. The method `{Class}::issue_notification(what: {NearestClass}Notification)`.
* This is the counterpart of `on_notification` to _send_ notifications.
* In GDScript, this is named `notification` (no underscore).
---
Apart from that, there are smaller changes:
* `Display` is now implemented on all `Gd<T>` types, by using the Godot string representation. `T`'s `Display` impl is ignored.
* Several generated symbols in `godot::engine` are now slighly documented and contain intra-doc links to navigate easily:
* Class <-> virtual trait
* Class <-> notification enum
* Class <-> sidecar module
* Class -> Godot online docs
* Modules `global`, `utilities` and `notify`
Co-authored-by: Jan Haller <[email protected]>
0 commit comments