Skip to content

Commit 72c8c0c

Browse files
committed
Merge branches 'qol/untyped-signal-connect', 'qol/cli-setup' and 'bugfix/gdscript-enums'
4 parents 35871a2 + a355192 + 9a0258c + 44d2ca4 commit 72c8c0c

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/intro/setup.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ For beta and older versions, you can also check the [download archive][godot-dow
2929

3030
```bash
3131
# --- Linux ---
32-
# For Ubuntu or Debian-based distros.
33-
apt install godot
34-
35-
# For Fedora/RHEL.
32+
# Fedora/RHEL.
3633
dnf install godot
3734

38-
# Distro-independent through Flatpak.
35+
# Arch Linux.
36+
pacman -Syu godot
37+
paru -Syu godot
38+
39+
# Flatpak (e.g. Ubuntu, Debian, or distro-independent).
3940
flatpak install flathub org.godotengine.Godot
4041

4142

4243
# --- Windows ---
43-
# Windows installations can be made through WinGet.
44-
winget install --id=GodotEngine.GodotEngine -e
44+
winget install -e --id GodotEngine.GodotEngine
45+
choco install godot
46+
scoop bucket add extras && scoop install godot
4547

4648

4749
# --- macOS ---
@@ -67,7 +69,7 @@ install it via command-line.
6769
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
6870

6971
# Windows
70-
winget install --id=Rustlang.Rustup -e
72+
winget install -e --id Rustlang.Rustup
7173

7274
# macOS
7375
brew install rustup

src/register/properties.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,21 @@ enum Planet {
162162
~~~
163163
is roughly the same as:
164164
~~~java
165-
const EARTH = 0
166-
const VENUS = 1
167-
const MARS = 2
165+
const Planet: Dictionary = {
166+
EARTH = 0,
167+
VENUS = 1,
168+
MARS = 2,
169+
}
168170
169171
@export_enum("EARTH", "VENUS", "MARS") var favorite_planet = Planet.EARTH
170172
~~~
171173
However, the enum is not type-safe, you can just do this:
172174
~~~java
173175
var p: Planet = 5
174176
~~~
175-
Furthermore, unless you initialize the constants with string values, you cannot retrieve their names, making debugging harder. There is no
176-
reflection either, such as "get number of enum values" or "iterate over all of them". If you have the choice, consider keeping enums in Rust.
177+
Furthermore, you can also not easily retrieve the name `"EARTH"` from the expression `Planet.EARTH`.[^enum-name]
178+
179+
See [GDScript enums][godot-gdscript-enums] for more details.
177180
```
178181

179182

@@ -212,3 +215,13 @@ As a general rule, try to stay close to Godot's own types, e.g. `Array`, `Dictio
212215
[api-var-export]: https://godot-rust.github.io/docs/gdext/master/godot/register/derive.GodotClass.html#properties-and-exports
213216
[godot-gdscript-properties]: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#properties
214217
[gh-godot-packedarray]: https://github.com/godotengine/godot/issues/76150
218+
[godot-gdscript-enums]: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#enums
219+
220+
<br>
221+
222+
---
223+
224+
**Footnotes**
225+
226+
[^enum-name]: You _can_ obtain `"EARTH"` if you iterate the `Planet` dictionary and compare each value (assuming there are no duplicates).
227+
That however requires that you know the type (`Planet`); the value itself does not hold this information.

src/register/signals.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,25 @@ The builder methods need to be called in the correct order ("stages"). See [API
443443

444444
Godot's low-level APIs for dealing with untyped signals are still available:
445445

446-
- [`Object::connect()`][api-object-connect], `Object::connect_ex()`
446+
- [`Object::connect()`][api-object-connect]
447+
- [`Object::connect_ex()`][api-object-connect-ex]
447448
- [`Object::emit_signal()`][api-object-emitsignal]
448449
- [`Signal::connect()`][api-signal-connect]
449450
- [`Signal::emit()`][api-signal-emit]
450451

451452
The new typed-signal API should cover the full functionality, but there are situations where information is only available at runtime, making
452453
the untyped reflection APIs a good fit. We might also combine the two in the future.
453454

454-
To emit an untyped signal, you can call the `Object::emit_signal` method by accessing the base class (mutably):
455-
Considering the `Monster` struct from the previous examples, you can emit its signal with:
455+
One way to connect signals the old-school is passing in the signal name and the `Callable`:
456+
457+
```rust
458+
let monster: Gd<Monster> = ...;
459+
let damage_taken: Callable = monster.callable("damage_taken");
460+
monster.connect("damage_taken", &damage_taken);
461+
```
462+
463+
To emit an untyped signal, call the `Object::emit_signal()` method by (mutably) accessing the base class.
464+
Staying with the `Monster` struct from the previous examples, you can emit its signal with:
456465

457466
```rust
458467
self.base_mut().emit_signal(
@@ -461,10 +470,11 @@ self.base_mut().emit_signal(
461470
);
462471
```
463472

464-
See [vslice!][api-vslice] docs for passing multiple variants in a slice.
473+
See [`vslice!`][api-vslice] docs for passing multiple variants in a slice.
465474

466-
Certain typed-signal features are still planned and will make working with signals even more streamlined. Other features are likely not going
467-
to be ported to godot-rust, e.g. a `Callable::bind()` equivalent for typed Rust methods. Just use closures instead.
475+
Certain untyped-signal functionality may still be ported typed signals, while others such as `Callable::bind()` will likely not be available.
476+
Just use closures instead. Generally speaking, the [`TypedSignal`][api-typedsignal] and [`ConnectBuilder`][api-connectbuilder] APIs are designed
477+
to be extensible for your own workflows.
468478

469479

470480
## Conclusion
@@ -483,6 +493,7 @@ Rust function references or closures can be directly connected to signals, and e
483493
[api-typedsignal-builder]: https://godot-rust.github.io/docs/gdext/master/godot/register/struct.TypedSignal.html#method.builder
484494
[api-connectbuilder]: https://godot-rust.github.io/docs/gdext/master/godot/register/struct.ConnectBuilder.html
485495
[api-object-connect]: https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Object.html#method.connect
496+
[api-object-connect-ex]: https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Object.html#method.connect_ex
486497
[api-object-emitsignal]: https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Object.html#method.emit_signal
487498
[api-signal-connect]: https://godot-rust.github.io/docs/gdext/master/godot/builtin/struct.Signal.html#method.connect
488499
[api-signal-emit]: https://godot-rust.github.io/docs/gdext/master/godot/builtin/struct.Signal.html#method.emit

0 commit comments

Comments
 (0)