Skip to content

Commit 73f37f6

Browse files
authored
Try #322:
2 parents 50e1401 + 6aaf808 commit 73f37f6

26 files changed

+1237
-311
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Hud {
2020
message_label.show();
2121

2222
let mut timer = self.base.get_node_as::<Timer>("MessageTimer");
23-
timer.start(0.0);
23+
timer.start();
2424
}
2525

2626
pub fn show_game_over(&self) {

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use crate::hud::Hud;
22
use crate::mob;
33
use crate::player;
4-
use godot::engine::node::InternalMode;
4+
55
use godot::engine::{Marker2D, PathFollow2D, RigidBody2D, Timer};
66
use godot::prelude::*;
7+
78
use rand::Rng as _;
8-
use std::f64::consts::PI;
9+
use std::f32::consts::PI;
910

1011
// Deriving GodotClass makes the class available to Godot
1112
#[derive(GodotClass)]
@@ -33,7 +34,7 @@ impl Main {
3334
hud.bind_mut().show_game_over();
3435

3536
self.music().stop();
36-
self.death_sound().play(0.0);
37+
self.death_sound().play();
3738
}
3839

3940
#[func]
@@ -45,22 +46,22 @@ impl Main {
4546
self.score = 0;
4647

4748
player.bind_mut().start(start_position.get_position());
48-
start_timer.start(0.0);
49+
start_timer.start();
4950

5051
let mut hud = self.base.get_node_as::<Hud>("Hud");
5152
let hud = hud.bind_mut();
5253
hud.update_score(self.score);
5354
hud.show_message("Get Ready".into());
5455

55-
self.music().play(0.0);
56+
self.music().play();
5657
}
5758

5859
#[func]
5960
fn on_start_timer_timeout(&self) {
6061
let mut mob_timer = self.base.get_node_as::<Timer>("MobTimer");
6162
let mut score_timer = self.base.get_node_as::<Timer>("ScoreTimer");
62-
mob_timer.start(0.0);
63-
score_timer.start(0.0);
63+
mob_timer.start();
64+
score_timer.start();
6465
}
6566

6667
#[func]
@@ -82,19 +83,15 @@ impl Main {
8283
let mut rng = rand::thread_rng();
8384
let progress = rng.gen_range(u32::MIN..u32::MAX);
8485

85-
mob_spawn_location.set_progress(progress.into());
86+
mob_spawn_location.set_progress(progress as f32);
8687
mob_scene.set_position(mob_spawn_location.get_position());
8788

8889
let mut direction = mob_spawn_location.get_rotation() + PI / 2.0;
8990
direction += rng.gen_range(-PI / 4.0..PI / 4.0);
9091

9192
mob_scene.set_rotation(direction);
9293

93-
self.base.add_child(
94-
mob_scene.share().upcast(),
95-
false,
96-
InternalMode::INTERNAL_MODE_DISABLED,
97-
);
94+
self.base.add_child(mob_scene.share().upcast());
9895

9996
let mut mob = mob_scene.cast::<mob::Mob>();
10097
{
@@ -103,15 +100,14 @@ impl Main {
103100
let range = rng.gen_range(mob.min_speed..mob.max_speed);
104101

105102
mob.set_linear_velocity(Vector2::new(range, 0.0));
106-
let lin_vel = mob.get_linear_velocity().rotated(real::from_f64(direction));
103+
let lin_vel = mob.get_linear_velocity().rotated(real::from_f32(direction));
107104
mob.set_linear_velocity(lin_vel);
108105
}
109106

110107
let mut hud = self.base.get_node_as::<Hud>("Hud");
111108
hud.bind_mut().connect(
112109
"start_game".into(),
113110
Callable::from_object_method(mob, "on_start_game"),
114-
0,
115111
);
116112
}
117113

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl RigidBody2DVirtual for Mob {
4040
.base
4141
.get_node_as::<AnimatedSprite2D>("AnimatedSprite2D");
4242

43-
sprite.play("".into(), 1.0, false);
43+
sprite.play();
4444
let anim_names = sprite.get_sprite_frames().unwrap().get_animation_names();
4545

4646
// TODO use pick_random() once implemented

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ impl Area2DVirtual for Player {
7474

7575
// Note: exact=false by default, in Rust we have to provide it explicitly
7676
let input = Input::singleton();
77-
if input.is_action_pressed("move_right".into(), false) {
77+
if input.is_action_pressed("move_right".into()) {
7878
velocity += Vector2::RIGHT;
7979
}
80-
if input.is_action_pressed("move_left".into(), false) {
80+
if input.is_action_pressed("move_left".into()) {
8181
velocity += Vector2::LEFT;
8282
}
83-
if input.is_action_pressed("move_down".into(), false) {
83+
if input.is_action_pressed("move_down".into()) {
8484
velocity += Vector2::DOWN;
8585
}
86-
if input.is_action_pressed("move_up".into(), false) {
86+
if input.is_action_pressed("move_up".into()) {
8787
velocity += Vector2::UP;
8888
}
8989

@@ -103,7 +103,7 @@ impl Area2DVirtual for Player {
103103
animated_sprite.set_flip_v(velocity.y > 0.0)
104104
}
105105

106-
animated_sprite.play(animation.into(), 1.0, false);
106+
animated_sprite.play_ex().name(animation.into()).done();
107107
} else {
108108
animated_sprite.stop();
109109
}

godot-codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["gamedev", "godot", "engine", "codegen"]
88
categories = ["game-engines", "graphics"]
99

1010
[features]
11-
default = []
11+
default = ["codegen-fmt"]
1212
codegen-fmt = []
1313
codegen-full = []
1414
double-precision = []

godot-codegen/src/api_parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,23 @@ pub struct MethodArg {
217217
pub name: String,
218218
#[nserde(rename = "type")]
219219
pub type_: String,
220-
// pub meta: Option<String>,
220+
pub meta: Option<String>,
221+
pub default_value: Option<String>,
221222
}
222223

223224
// Example: get_available_point_id -> {type: "int", meta: "int64"}
224225
#[derive(DeJson, Clone)]
225226
pub struct MethodReturn {
226227
#[nserde(rename = "type")]
227228
pub type_: String,
228-
// pub meta: Option<String>,
229+
pub meta: Option<String>,
229230
}
230231

231232
impl MethodReturn {
232-
pub fn from_type(type_: &str) -> Self {
233+
pub fn from_type_no_meta(type_: &str) -> Self {
233234
Self {
234235
type_: type_.to_owned(),
236+
meta: None,
235237
}
236238
}
237239
}

godot-codegen/src/central_generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn make_enumerator(
498498
) -> (Ident, TokenStream, Literal) {
499499
let enumerator_name = &type_names.json_builtin_name;
500500
let pascal_name = to_pascal_case(enumerator_name);
501-
let rust_ty = to_rust_type(enumerator_name, ctx);
501+
let rust_ty = to_rust_type(enumerator_name, None, ctx);
502502
let ord = Literal::i32_unsuffixed(value);
503503

504504
(ident(&pascal_name), rust_ty.to_token_stream(), ord)

0 commit comments

Comments
 (0)