-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Signals now accept parameters #279
Conversation
Thanks! 🙂 Can you show some usage examples here (so people don't have to download the archive)? |
player.rs: #[signal]
fn test(direction: Vector2);
fn on_player_body_entered(&mut self, _body: Gd<PhysicsBody2D>) {
...
let pos = self.get_position();
self.base.emit_signal("test".into(), &[pos.to_variant()]);
} main_scene.rs: #[func]
pub fn new_game(&mut self) {
...
let mut player = self.base.get_node_as::<player::Player>("Player");
player.bind_mut().connect(
"test".into(),
Callable::from_object_method(self.base.get_node_as::<Self>("."), "test_function"),
0,
);
}
#[func]
fn test_function(&self, direction: Vector2) {
println!("Player died at: {}", direction);
} Gravacao.de.tela.de.2023-05-18.08-31-44.webm |
With 2 parameters: #[signal]
fn test(direction: Vector2, distance: f32);
#[func]
fn on_player_body_entered(&mut self, _body: Gd<PhysicsBody2D>) {
...
self.base.emit_signal("test".into(), &[pos.to_variant(), pos.length().to_variant()]);
} main_scene.rs: #[func]
fn test_function(&self, direction: Vector2, distance: f32) {
println!("Player died at: {} (distance {} from (0, 0))", direction, distance);
} Gravacao.de.tela.de.2023-05-18.08-39-44.webm |
bors try |
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-279 |
tryBuild succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
ddcdc6a
to
b1817c2
Compare
b1817c2
to
5b0cb19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the update! Added smaller comments. Since there is now quite a bit of signal functionality, you can also consider adding a new signal_test.rs
file for these tests (don't forget license header). Or leave it as-is, if you prefer 🙂
Could you integrate your changes into the 2nd commit?
itest/rust/src/object_test.rs
Outdated
emitter | ||
.share() | ||
.upcast::<Object>() | ||
.emit_signal(signal_name.into(), arg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emitter | |
.share() | |
.upcast::<Object>() | |
.emit_signal(signal_name.into(), arg); | |
emitter.base.emit_signal(signal_name.into(), arg); |
It's in the same file and for a test, so encapsulation is not the highest priority.
itest/rust/src/object_test.rs
Outdated
self.used[2].set(true); | ||
assert_eq!(self.base.share(), arg1); | ||
assert_eq!(SIGNAL_ARG_STRING, arg2.to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to check the preconditions first and separate them with an empty line from the logic.
Same above.
self.used[2].set(true); | |
assert_eq!(self.base.share(), arg1); | |
assert_eq!(SIGNAL_ARG_STRING, arg2.to_string()); | |
assert_eq!(self.base.share(), arg1); | |
assert_eq!(SIGNAL_ARG_STRING, arg2.to_string()); | |
self.used[2].set(true); |
itest/rust/src/object_test.rs
Outdated
let emitter: Gd<SignalEmitter> = Gd::new_default(); | ||
let receiver: Gd<SignalReceiver> = Gd::new_default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let emitter: Gd<SignalEmitter> = Gd::new_default(); | |
let receiver: Gd<SignalReceiver> = Gd::new_default(); | |
let emitter = Gd::<SignalEmitter>::new_default(); | |
let receiver = Gd::<SignalReceiver>::new_default(); |
Turbofish! 🐟💨
itest/rust/src/object_test.rs
Outdated
let signal_name = format!("signal_{}_arg", i); | ||
let receiver_name = format!("receive_{}_arg", i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let signal_name = format!("signal_{}_arg", i); | |
let receiver_name = format!("receive_{}_arg", i); | |
let signal_name = format!("signal_{i}_arg"); | |
let receiver_name = format!("receive_{i}_arg"); |
itest/rust/src/object_test.rs
Outdated
let signal_name = format!("signal_{}_arg", i); | ||
let receiver_name = format!("receive_{}_arg", i); | ||
|
||
emitter.share().upcast::<Object>().connect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emitter.share().upcast::<Object>().connect( | |
emitter.base.connect( |
bors try |
tryBuild succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
5b0cb19
to
069b647
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
bors r+
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Project for testing: