Skip to content

Commit 799c3f5

Browse files
authored
Merge pull request #733 from godot-rust/qol/streamline-modules-3
Streamline modules - part III: `godot::classes`, `godot::tools`, `godot::obj::script`
2 parents 1e9ea80 + 9345010 commit 799c3f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+435
-398
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{Button, CanvasLayer, ICanvasLayer, Label, Timer};
1+
use godot::classes::{Button, CanvasLayer, ICanvasLayer, Label, Timer};
22
use godot::prelude::*;
33

44
#[derive(GodotClass)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::hud::Hud;
22
use crate::mob;
33
use crate::player;
44

5-
use godot::engine::{Marker2D, PathFollow2D, RigidBody2D, Timer};
5+
use godot::classes::{Marker2D, PathFollow2D, RigidBody2D, Timer};
66
use godot::prelude::*;
77

88
use rand::Rng as _;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{AnimatedSprite2D, IRigidBody2D, RigidBody2D};
1+
use godot::classes::{AnimatedSprite2D, IRigidBody2D, RigidBody2D};
22
use godot::prelude::*;
33
use rand::seq::SliceRandom;
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use godot::engine::{AnimatedSprite2D, Area2D, CollisionShape2D, IArea2D, PhysicsBody2D};
1+
use godot::classes::{AnimatedSprite2D, Area2D, CollisionShape2D, IArea2D, PhysicsBody2D};
22
use godot::prelude::*;
33

44
#[derive(GodotClass)]

godot-codegen/src/conv/type_conversions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn to_rust_type_uncached(full_ty: &GodotTy, ctx: &mut Context) -> RustTy {
164164
let bitfield_ty = conv::make_enum_name(enum_);
165165

166166
RustTy::EngineBitfield {
167-
tokens: quote! { crate::engine::#module::#bitfield_ty},
167+
tokens: quote! { crate::classes::#module::#bitfield_ty},
168168
surrounding_class: Some(class.to_string()),
169169
}
170170
} else {
@@ -185,7 +185,7 @@ fn to_rust_type_uncached(full_ty: &GodotTy, ctx: &mut Context) -> RustTy {
185185
let enum_ty = conv::make_enum_name(enum_);
186186

187187
RustTy::EngineEnum {
188-
tokens: quote! { crate::engine::#module::#enum_ty },
188+
tokens: quote! { crate::classes::#module::#enum_ty },
189189
surrounding_class: Some(class.to_string()),
190190
}
191191
} else {
@@ -221,7 +221,7 @@ fn to_rust_type_uncached(full_ty: &GodotTy, ctx: &mut Context) -> RustTy {
221221
} else {
222222
let ty = rustify_ty(ty);
223223
RustTy::EngineClass {
224-
tokens: quote! { Gd<crate::engine::#ty> },
224+
tokens: quote! { Gd<crate::classes::#ty> },
225225
inner_class: ty,
226226
}
227227
}

godot-codegen/src/generator/central_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn make_core_central_code(api: &ExtensionApi, ctx: &mut Context) -> TokenStr
6767
// But this requires that all the variant types support this.
6868
quote! {
6969
use crate::builtin::*;
70-
use crate::engine::Object;
70+
use crate::classes::Object;
7171
use crate::obj::Gd;
7272

7373
// Remaining trait impls for sys::VariantType (traits only defined in godot-core).

godot-codegen/src/generator/classes.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
8484
let (base_ty, base_ident_opt) = match class.inherits.as_ref() {
8585
Some(base) => {
8686
let base = ident(&conv::to_pascal_case(base));
87-
(quote! { crate::engine::#base }, Some(base))
87+
(quote! { crate::classes::#base }, Some(base))
8888
}
8989
None => (quote! { crate::obj::NoBase }, None),
9090
};
@@ -132,7 +132,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
132132
notifications::make_notification_enum(class_name, &all_bases, &cfg_attributes, ctx);
133133

134134
// Associated "sidecar" module is made public if there are other symbols related to the class, which are not
135-
// in top-level godot::engine module (notification enums are not in the sidecar, but in godot::engine::notify).
135+
// in top-level godot::classes module (notification enums are not in the sidecar, but in godot::classes::notify).
136136
// This checks if token streams (i.e. code) is empty.
137137
let has_sidecar_module = !enums.is_empty() || !builders.is_empty();
138138

@@ -184,7 +184,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
184184
#cfg_inner_attributes
185185

186186
#imports
187-
use crate::engine::notify::*;
187+
use crate::classes::notify::*;
188188
use std::ffi::c_void;
189189

190190
pub(super) mod re_export {
@@ -228,7 +228,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
228228

229229
#(
230230
// SAFETY: #all_bases is a list of classes provided by Godot such that #class_name is guaranteed a subclass of all of them.
231-
unsafe impl crate::obj::Inherits<crate::engine::#all_bases> for #class_name {}
231+
unsafe impl crate::obj::Inherits<crate::classes::#all_bases> for #class_name {}
232232
)*
233233

234234
#godot_default_impl
@@ -241,9 +241,9 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
241241
#[allow(non_snake_case)]
242242
macro_rules! #inherits_macro {
243243
($Class:ident) => {
244-
unsafe impl ::godot::obj::Inherits<::godot::engine::#class_name> for $Class {}
244+
unsafe impl ::godot::obj::Inherits<::godot::classes::#class_name> for $Class {}
245245
#(
246-
unsafe impl ::godot::obj::Inherits<::godot::engine::#all_bases> for $Class {}
246+
unsafe impl ::godot::obj::Inherits<::godot::classes::#all_bases> for $Class {}
247247
)*
248248
}
249249
}
@@ -313,6 +313,7 @@ fn make_class_module_file(classes_and_modules: Vec<GeneratedClassModule>) -> Tok
313313
quote! {
314314
#( #class_decls )*
315315

316+
/// Notification enums for all classes.
316317
pub mod notify {
317318
#( #notify_decls )*
318319
}
@@ -380,7 +381,7 @@ fn make_constructor_and_default(
380381
quote! {
381382
impl crate::obj::cap::GodotDefault for #class_name {
382383
fn __godot_default() -> crate::obj::Gd<Self> {
383-
crate::engine::construct_engine_object::<Self>()
384+
crate::classes::construct_engine_object::<Self>()
384385
}
385386
}
386387
}

godot-codegen/src/generator/docs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ pub fn make_class_doc(
2222
let TyName { rust_ty, godot_ty } = class_name;
2323

2424
let inherits_line = if let Some(base) = base_ident_opt {
25-
format!("Inherits [`{base}`][crate::engine::{base}].")
25+
format!("Inherits [`{base}`][crate::classes::{base}].")
2626
} else {
2727
"This is the base class for all other classes at the root of the hierarchy. \
2828
Every instance of `Object` can be stored in a [`Gd`][crate::obj::Gd] smart pointer."
2929
.to_string()
3030
};
3131

3232
let notify_line = if has_notification_enum {
33-
format!("* [`{rust_ty}Notification`][crate::engine::notify::{rust_ty}Notification]: notification type\n")
33+
format!("* [`{rust_ty}Notification`][crate::classes::notify::{rust_ty}Notification]: notification type\n")
3434
} else {
3535
String::new()
3636
};
3737

3838
let sidecar_line = if has_sidecar_module {
3939
let module_name = ModName::from_godot(&class_name.godot_ty).rust_mod;
40-
format!("* [`{module_name}`][crate::engine::{module_name}]: sidecar module with related enum/flag types\n")
40+
format!("* [`{module_name}`][crate::classes::{module_name}]: sidecar module with related enum/flag types\n")
4141
} else {
4242
String::new()
4343
};
@@ -60,7 +60,7 @@ pub fn make_class_doc(
6060
\
6161
Related symbols:\n\n\
6262
{sidecar_line}\
63-
* [`{trait_name}`][crate::engine::{trait_name}]: virtual methods\n\
63+
* [`{trait_name}`][crate::classes::{trait_name}]: virtual methods\n\
6464
{notify_line}\
6565
\n\n\
6666
See also [Godot docs for `{godot_ty}`]({online_link}).\n\n{notes}",
@@ -80,7 +80,7 @@ pub fn make_virtual_trait_doc(trait_name_str: &str, class_name: &TyName) -> Stri
8080
.unwrap_or_default();
8181

8282
format!(
83-
"Virtual methods for class [`{rust_ty}`][crate::engine::{rust_ty}].\
83+
"Virtual methods for class [`{rust_ty}`][crate::classes::{rust_ty}].\
8484
\n\n\
8585
These methods represent constructors (`init`) or callbacks invoked by the engine.\
8686
\n\n\
@@ -97,7 +97,7 @@ pub fn make_module_doc(class_name: &TyName) -> String {
9797
);
9898

9999
format!(
100-
"Sidecar module for class [`{rust_ty}`][crate::engine::{rust_ty}].\
100+
"Sidecar module for class [`{rust_ty}`][crate::classes::{rust_ty}].\
101101
\n\n\
102102
Defines related flag and enum types. In GDScript, those are nested under the class scope.\
103103
\n\n\

godot-codegen/src/generator/gdext_build_struct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn make_gdext_build_struct(header: &GodotApiVersion) -> TokenStream {
5353
(version.major as u8, version.minor as u8, version.patch as u8)
5454
}
5555

56-
/// For a string "4.x", returns `true` if the current Godot version is strictly less than 4.x.
56+
/// For a string `"4.x"`, returns `true` if the current Godot version is strictly less than 4.x.
5757
///
5858
/// Runtime equivalent of `#[cfg(before_api = "4.x")]`.
5959
///
@@ -69,7 +69,7 @@ pub fn make_gdext_build_struct(header: &GodotApiVersion) -> TokenStream {
6969
minor < queried_minor
7070
}
7171

72-
/// For a string "4.x", returns `true` if the current Godot version is equal or greater to 4.x.
72+
/// For a string `"4.x"`, returns `true` if the current Godot version is equal or greater to 4.x.
7373
///
7474
/// Runtime equivalent of `#[cfg(since_api = "4.x")]`.
7575
///

godot-codegen/src/generator/notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn make_notification_enum(
8181

8282
let enum_name = ctx.notification_enum_name(class_name).name;
8383
let doc_str = format!(
84-
"Notification type for class [`{c}`][crate::engine::{c}].",
84+
"Notification type for class [`{c}`][crate::classes::{c}].",
8585
c = class_name.rust_ty
8686
);
8787

0 commit comments

Comments
 (0)