Skip to content

Commit

Permalink
Apply new argument passing across examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Nov 3, 2024
1 parent 756a922 commit a4c874e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions examples/dodge-the-creeps/rust/src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Hud {
#[func]
pub fn show_message(&self, text: GString) {
let mut message_label = self.base().get_node_as::<Label>("MessageLabel");
message_label.set_text(text);
message_label.set_text(&text);
message_label.show();

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

let mut timer = self.base().get_tree().unwrap().create_timer(2.0).unwrap();
timer.connect("timeout".into(), self.base().callable("show_start_button"));
timer.connect("timeout", self.base().callable("show_start_button"));
}

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

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

label.set_text(score.to_string().into());
label.set_text(&score.to_string());
}

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

#[func]
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge-the-creeps/rust/src/main_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Main {
mob.set_linear_velocity(Vector2::new(range, 0.0).rotated(real::from_f32(direction)));

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

fn music(&mut self) -> &mut AudioStreamPlayer {
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge-the-creeps/rust/src/mob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ impl IRigidBody2D for Mob {
let mut rng = rand::thread_rng();
let animation_name = anim_names.choose(&mut rng).unwrap();

sprite.set_animation(animation_name.into());
sprite.set_animation(animation_name.arg());
}
}
14 changes: 7 additions & 7 deletions examples/dodge-the-creeps/rust/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ impl Player {
#[func]
fn on_player_body_entered(&mut self, _body: Gd<PhysicsBody2D>) {
self.base_mut().hide();
self.base_mut().emit_signal("hit".into(), &[]);
self.base_mut().emit_signal("hit", &[]);

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

collision_shape.set_deferred("disabled".into(), &true.to_variant());
collision_shape.set_deferred("disabled", &true.to_variant());
}

#[func]
Expand Down Expand Up @@ -65,16 +65,16 @@ impl IArea2D for Player {

// Note: exact=false by default, in Rust we have to provide it explicitly
let input = Input::singleton();
if input.is_action_pressed("move_right".into()) {
if input.is_action_pressed("move_right") {
velocity += Vector2::RIGHT;
}
if input.is_action_pressed("move_left".into()) {
if input.is_action_pressed("move_left") {
velocity += Vector2::LEFT;
}
if input.is_action_pressed("move_down".into()) {
if input.is_action_pressed("move_down") {
velocity += Vector2::DOWN;
}
if input.is_action_pressed("move_up".into()) {
if input.is_action_pressed("move_up") {
velocity += Vector2::UP;
}

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

animated_sprite.play_ex().name(animation.into()).done();
animated_sprite.play_ex().name(animation).done();
} else {
animated_sprite.stop();
}
Expand Down

0 comments on commit a4c874e

Please sign in to comment.