Skip to content

Commit a4c874e

Browse files
committed
Apply new argument passing across examples
1 parent 756a922 commit a4c874e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

examples/dodge-the-creeps/rust/src/hud.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Hud {
1515
#[func]
1616
pub fn show_message(&self, text: GString) {
1717
let mut message_label = self.base().get_node_as::<Label>("MessageLabel");
18-
message_label.set_text(text);
18+
message_label.set_text(&text);
1919
message_label.show();
2020

2121
let mut timer = self.base().get_node_as::<Timer>("MessageTimer");
@@ -26,13 +26,13 @@ impl Hud {
2626
self.show_message("Game Over".into());
2727

2828
let mut timer = self.base().get_tree().unwrap().create_timer(2.0).unwrap();
29-
timer.connect("timeout".into(), self.base().callable("show_start_button"));
29+
timer.connect("timeout", self.base().callable("show_start_button"));
3030
}
3131

3232
#[func]
3333
fn show_start_button(&mut self) {
3434
let mut message_label = self.base().get_node_as::<Label>("MessageLabel");
35-
message_label.set_text("Dodge the\nCreeps!".into());
35+
message_label.set_text("Dodge the\nCreeps!");
3636
message_label.show();
3737

3838
let mut button = self.base().get_node_as::<Button>("StartButton");
@@ -43,7 +43,7 @@ impl Hud {
4343
pub fn update_score(&self, score: i64) {
4444
let mut label = self.base().get_node_as::<Label>("ScoreLabel");
4545

46-
label.set_text(score.to_string().into());
46+
label.set_text(&score.to_string());
4747
}
4848

4949
#[func]
@@ -55,7 +55,7 @@ impl Hud {
5555
// This method keeps a &mut Hud, and start_game calls Main::new_game(), which itself accesses this Hud
5656
// instance through Gd<Hud>::bind_mut(). It will try creating a 2nd &mut reference, and thus panic.
5757
// Deferring the signal is one option to work around it.
58-
self.base_mut().emit_signal("start_game".into(), &[]);
58+
self.base_mut().emit_signal("start_game", &[]);
5959
}
6060

6161
#[func]

examples/dodge-the-creeps/rust/src/main_scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Main {
102102
mob.set_linear_velocity(Vector2::new(range, 0.0).rotated(real::from_f32(direction)));
103103

104104
let mut hud = self.base().get_node_as::<Hud>("Hud");
105-
hud.connect("start_game".into(), mob.callable("on_start_game"));
105+
hud.connect("start_game", mob.callable("on_start_game"));
106106
}
107107

108108
fn music(&mut self) -> &mut AudioStreamPlayer {

examples/dodge-the-creeps/rust/src/mob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ impl IRigidBody2D for Mob {
4747
let mut rng = rand::thread_rng();
4848
let animation_name = anim_names.choose(&mut rng).unwrap();
4949

50-
sprite.set_animation(animation_name.into());
50+
sprite.set_animation(animation_name.arg());
5151
}
5252
}

examples/dodge-the-creeps/rust/src/player.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ impl Player {
1818
#[func]
1919
fn on_player_body_entered(&mut self, _body: Gd<PhysicsBody2D>) {
2020
self.base_mut().hide();
21-
self.base_mut().emit_signal("hit".into(), &[]);
21+
self.base_mut().emit_signal("hit", &[]);
2222

2323
let mut collision_shape = self
2424
.base()
2525
.get_node_as::<CollisionShape2D>("CollisionShape2D");
2626

27-
collision_shape.set_deferred("disabled".into(), &true.to_variant());
27+
collision_shape.set_deferred("disabled", &true.to_variant());
2828
}
2929

3030
#[func]
@@ -65,16 +65,16 @@ impl IArea2D for Player {
6565

6666
// Note: exact=false by default, in Rust we have to provide it explicitly
6767
let input = Input::singleton();
68-
if input.is_action_pressed("move_right".into()) {
68+
if input.is_action_pressed("move_right") {
6969
velocity += Vector2::RIGHT;
7070
}
71-
if input.is_action_pressed("move_left".into()) {
71+
if input.is_action_pressed("move_left") {
7272
velocity += Vector2::LEFT;
7373
}
74-
if input.is_action_pressed("move_down".into()) {
74+
if input.is_action_pressed("move_down") {
7575
velocity += Vector2::DOWN;
7676
}
77-
if input.is_action_pressed("move_up".into()) {
77+
if input.is_action_pressed("move_up") {
7878
velocity += Vector2::UP;
7979
}
8080

@@ -94,7 +94,7 @@ impl IArea2D for Player {
9494
animated_sprite.set_flip_v(velocity.y > 0.0)
9595
}
9696

97-
animated_sprite.play_ex().name(animation.into()).done();
97+
animated_sprite.play_ex().name(animation).done();
9898
} else {
9999
animated_sprite.stop();
100100
}

0 commit comments

Comments
 (0)