Skip to content

Commit f3b0150

Browse files
committed
hot-reload: use #[class(init)]
1 parent 9ade9bd commit f3b0150

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

hot-reload/rust/src/lib.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,31 @@ struct HotReload;
1111

1212
#[gdextension]
1313
unsafe impl ExtensionLibrary for HotReload {
14-
fn on_level_init(_level: InitLevel) {
15-
println!("[Rust] Init level {:?}", _level);
14+
fn on_level_init(level: InitLevel) {
15+
println!("[Rust] Init level {level:?}");
1616
}
1717

18-
fn on_level_deinit(_level: InitLevel) {
19-
println!("[Rust] Deinit level {:?}", _level);
18+
fn on_level_deinit(level: InitLevel) {
19+
println!("[Rust] Deinit level {level:?}");
2020
}
2121
}
2222

2323
// ----------------------------------------------------------------------------------------------------------------------------------------------
2424

2525
/// A RustDoc comment appearing under the editor help docs.
2626
#[derive(GodotClass)]
27-
#[class(base=Node)]
27+
#[class(init, base=Node)]
2828
struct Reloadable {
2929
/// A planet!
3030
#[export]
31+
#[init(val = Planet::Earth)]
3132
favorite_planet: Planet,
3233
//
3334
// HOT-RELOAD: uncomment this to add a new exported field (also update init() below).
3435
// #[export]
3536
// some_string: GString,
3637
}
3738

38-
#[godot_api]
39-
impl INode for Reloadable {
40-
fn init(_base: Base<Self::Base>) -> Self {
41-
// HOT-RELOAD: change values to initialize with different defaults.
42-
Self {
43-
favorite_planet: Planet::Earth,
44-
//some_string: "Hello, world!".into(),
45-
}
46-
}
47-
}
48-
4939
#[godot_api]
5040
impl Reloadable {
5141
/// A function to return a number.
@@ -55,19 +45,18 @@ impl Reloadable {
5545
100
5646
}
5747

58-
/// Constructor from a string.
48+
// HOT-RELOAD: uncomment to make new function accessible.
49+
5950
#[func]
60-
fn from_string(s: GString) -> Gd<Self> {
61-
Gd::from_object(Reloadable {
62-
favorite_planet: Planet::from_godot(s),
63-
})
51+
fn get_planet(&self) -> Planet {
52+
self.favorite_planet
6453
}
6554
}
6655

6756
// ----------------------------------------------------------------------------------------------------------------------------------------------
6857

6958
/// A planet enum.
70-
#[derive(GodotConvert, Var, Export)]
59+
#[derive(GodotConvert, Var, Export, Copy, Clone, Debug)]
7160
#[godot(via = GString)]
7261
enum Planet {
7362
Earth,

0 commit comments

Comments
 (0)