Skip to content

Commit 0c9052a

Browse files
committed
More consistency updates in godot::builtin module
1 parent 4295698 commit 0c9052a

File tree

14 files changed

+99
-62
lines changed

14 files changed

+99
-62
lines changed

godot-codegen/src/generator/central_files.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn make_core_central_code(api: &ExtensionApi, ctx: &mut Context) -> TokenStr
5959
..
6060
} = make_variant_enums(api, ctx);
6161

62-
let global_enum_defs = make_global_enums(api);
62+
let (global_enum_defs, global_reexported_enum_defs) = make_global_enums(api);
6363
let variant_type_traits = make_variant_type_enum(api, false).0;
6464

6565
// TODO impl Clone, Debug, PartialEq, PartialOrd, Hash for VariantDispatch
@@ -107,16 +107,16 @@ pub fn make_core_central_code(api: &ExtensionApi, ctx: &mut Context) -> TokenStr
107107
}
108108
}
109109

110-
/// Global enums and constants.
111-
///
112-
/// A list of global-scope enumerated constants.
113-
/// For global built-in functions, check out the [`utilities` module][crate::engine::utilities].
114-
///
115-
/// See also [Godot docs for `@GlobalScope`](https://docs.godotengine.org/en/stable/classes/class_@globalscope.html#enumerations).
110+
/// Global enums and constants, generated by Godot.
116111
pub mod global_enums {
117112
use crate::sys;
118113
#( #global_enum_defs )*
119114
}
115+
116+
pub mod global_reexported_enums {
117+
use crate::sys;
118+
#( #global_reexported_enum_defs )*
119+
}
120120
}
121121
}
122122

@@ -183,8 +183,9 @@ fn make_variant_enums(api: &ExtensionApi, ctx: &mut Context) -> VariantEnums {
183183
result
184184
}
185185

186-
fn make_global_enums(api: &ExtensionApi) -> Vec<TokenStream> {
186+
fn make_global_enums(api: &ExtensionApi) -> (Vec<TokenStream>, Vec<TokenStream>) {
187187
let mut global_enum_defs = vec![];
188+
let mut global_reexported_enum_defs = vec![];
188189

189190
for enum_ in api.global_enums.iter() {
190191
// Skip VariantType, which is already defined in godot-ffi.
@@ -193,10 +194,15 @@ fn make_global_enums(api: &ExtensionApi) -> Vec<TokenStream> {
193194
}
194195

195196
let def = enums::make_enum_definition(enum_);
196-
global_enum_defs.push(def);
197+
198+
if enum_.is_private {
199+
global_reexported_enum_defs.push(def);
200+
} else {
201+
global_enum_defs.push(def);
202+
}
197203
}
198204

199-
global_enum_defs
205+
(global_enum_defs, global_reexported_enum_defs)
200206
}
201207

202208
fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStream, TokenStream) {

godot-codegen/src/generator/enums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn make_enum_definition_with(
7272
// Non-exhaustive enums are declared as newtype structs with associated constants.
7373
else {
7474
// Workaround because traits are defined in separate crate, but need access to field `ord`.
75-
let vis = (!define_traits).then(|| {
75+
let ord_vis = (!define_traits).then(|| {
7676
quote! { #[doc(hidden)] pub }
7777
});
7878

@@ -82,7 +82,7 @@ pub fn make_enum_definition_with(
8282
#[derive( #( #derives ),* )]
8383
#( #[doc = #enum_doc] )*
8484
pub struct #name {
85-
#vis ord: #ord_type
85+
#ord_vis ord: #ord_type
8686
}
8787

8888
impl #name {

godot-codegen/src/models/domain/enums.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct Enum {
1818
pub name: Ident,
1919
pub godot_name: String,
2020
pub is_bitfield: bool,
21+
pub is_private: bool,
2122
pub is_exhaustive: bool,
2223
pub enumerators: Vec<Enumerator>,
2324
}

godot-codegen/src/models/domain_mapping.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ impl Enum {
526526
pub fn from_json(json_enum: &JsonEnum, surrounding_class: Option<&TyName>) -> Self {
527527
let godot_name = &json_enum.name;
528528
let is_bitfield = json_enum.is_bitfield;
529+
let is_private = special_cases::is_enum_private(surrounding_class, godot_name);
529530
let is_exhaustive = special_cases::is_enum_exhaustive(surrounding_class, godot_name);
530531

531532
let rust_enum_name = conv::make_enum_name_str(godot_name);
@@ -560,6 +561,7 @@ impl Enum {
560561
name: ident(&rust_enum_name),
561562
godot_name: godot_name.clone(),
562563
is_bitfield,
564+
is_private,
563565
is_exhaustive,
564566
enumerators,
565567
}

godot-codegen/src/special_cases/special_cases.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,21 @@ pub fn is_class_level_server(class_name: &str) -> bool {
362362
}
363363
}
364364

365+
/// Whether a generated enum is `pub(crate)`; useful for manual re-exports.
366+
#[rustfmt::skip]
367+
pub fn is_enum_private(class_name: Option<&TyName>, enum_name: &str) -> bool {
368+
match (class_name, enum_name) {
369+
// Re-exported to godot::builtin.
370+
| (None, "Corner")
371+
| (None, "EulerOrder")
372+
| (None, "Side")
373+
| (None, "Variant.Operator")
374+
| (None, "Variant.Type")
375+
376+
=> true, _ => false
377+
}
378+
}
379+
365380
/// Certain enums that are extremely unlikely to get new identifiers in the future.
366381
///
367382
/// `class_name` = None for global enums.

godot-core/src/builtin/color.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8+
use crate::builtin::color_hsv::rgba_to_hsva;
89
use crate::builtin::inner::InnerColor;
910
use crate::builtin::math::ApproxEq;
10-
use crate::builtin::GString;
11-
11+
use crate::builtin::meta::impl_godot_as_self;
12+
use crate::builtin::{ColorHsv, GString};
1213
use godot_ffi as sys;
13-
use sys::{ffi_methods, GodotFfi};
14-
1514
use std::ops;
16-
17-
use super::meta::impl_godot_as_self;
18-
use super::{rgba_to_hsva, ColorHsv};
15+
use sys::{ffi_methods, GodotFfi};
1916

2017
/// Color built-in type, in floating-point RGBA format.
2118
///
2219
/// Channel values are _typically_ in the range of 0 to 1, but this is not a requirement, and
2320
/// values outside this range are explicitly allowed for e.g. High Dynamic Range (HDR).
2421
///
25-
/// To access its [**HSVA**](super::ColorHsv) representation, use [`Color::to_hsv`].
22+
/// To access its [**HSVA**](ColorHsv) representation, use [`Color::to_hsv`].
2623
#[repr(C)]
2724
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
2825
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@@ -100,8 +97,8 @@ impl Color {
10097
/// Constructs a `Color` from a string, which can be either:
10198
///
10299
/// - An HTML color code as accepted by [`Color::from_html`].
103-
/// - The name of a built-in color constant, such as `BLUE` or `lawn-green`. Matching is case
104-
/// insensitive and hyphens can be used interchangeably with underscores. See the [list of
100+
/// - The name of a built-in color constant, such as `BLUE` or `lawn-green`. Matching is case-insensitive
101+
/// and hyphens can be used interchangeably with underscores. See the [list of
105102
/// color constants][color_constants] in the Godot API documentation, or the visual [cheat
106103
/// sheet][cheat_sheet] for the full list.
107104
///
@@ -365,6 +362,7 @@ impl ApproxEq for Color {
365362
}
366363
}
367364

365+
/// Defines how individual color channels are laid out in memory.
368366
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
369367
pub enum ColorChannelOrder {
370368
/// RGBA channel order. Godot's default.
@@ -566,7 +564,7 @@ impl std::fmt::Display for Color {
566564
/// # Example
567565
/// ```
568566
/// use godot::prelude::*;
569-
/// let color = Color::from_rgba(1.0,1.0,1.0,1.0);
567+
/// let color = Color::from_rgba(1.0, 1.0, 1.0, 1.0);
570568
/// assert_eq!(format!("{}", color), "(1, 1, 1, 1)");
571569
/// ```
572570
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

godot-core/src/builtin/color_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use crate::builtin::Color;
99

10-
/// Godot's predefined colors
10+
/// Godot's predefined colors.
1111
///
1212
/// This [visual cheat sheet](https://raw.githubusercontent.com/godotengine/godot-docs/master/img/color_constants.png)
1313
/// shows how the colors look.

godot-core/src/builtin/meta/godot_convert/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ pub trait ToGodot: Sized + GodotConvert {
5757

5858
/// Defines the canonical conversion from Godot for a type.
5959
///
60-
/// It is assumed that all the methods return equal values given equal inputs. Additionally it is assumed
60+
/// It is assumed that all the methods return equal values given equal inputs. Additionally, it is assumed
6161
/// that if [`ToGodot`] is implemented, converting to Godot and back again will return a value equal to the
6262
/// starting value.
6363
///
6464
/// Violating these assumptions is safe but will give unexpected results.
6565
pub trait FromGodot: Sized + GodotConvert {
66-
/// Performs the conversion.
66+
/// Converts the Godot representation to this type, returning `Err` on failure.
6767
fn try_from_godot(via: Self::Via) -> Result<Self, ConvertError>;
6868

69-
/// ⚠️ Performs the conversion.
69+
/// ⚠️ Converts the Godot representation to this type.
7070
///
7171
/// # Panics
7272
/// If the conversion fails.
@@ -75,7 +75,7 @@ pub trait FromGodot: Sized + GodotConvert {
7575
.unwrap_or_else(|err| panic!("FromGodot::from_godot() failed: {err}"))
7676
}
7777

78-
/// Performs the conversion from a [`Variant`].
78+
/// Performs the conversion from a [`Variant`], returning `Err` on failure.
7979
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError> {
8080
let ffi = <Self::Via as GodotType>::Ffi::ffi_from_variant(variant)?;
8181

godot-core/src/builtin/mod.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,42 @@
3636
// Re-export macros.
3737
pub use crate::{array, dict, real, reals, varray};
3838

39+
// Re-export generated enums.
40+
pub use crate::gen::central::global_reexported_enums::{Corner, EulerOrder, Side, VariantOperator};
41+
pub use crate::sys::VariantType;
42+
// Not yet public.
43+
pub(crate) use crate::gen::central::VariantDispatch;
44+
3945
#[doc(hidden)]
4046
pub mod __prelude_reexport {
4147
use super::*;
4248

43-
pub use aabb::*;
49+
pub use aabb::Aabb;
4450
pub use array_inner::{Array, VariantArray};
45-
pub use basis::*;
46-
pub use callable::*;
47-
pub use color::*;
48-
pub use color_hsv::*;
51+
pub use basis::Basis;
52+
pub use callable::{Callable, RustCallable};
53+
pub use color::{Color, ColorChannelOrder};
54+
pub use color_hsv::ColorHsv;
4955
pub use dictionary_inner::Dictionary;
5056
pub use packed_array::*;
51-
pub use plane::*;
52-
pub use projection::*;
53-
pub use quaternion::*;
57+
pub use plane::Plane;
58+
pub use projection::{Projection, ProjectionEye, ProjectionPlane};
59+
pub use quaternion::Quaternion;
5460
pub use real_inner::*;
55-
pub use rect2::*;
56-
pub use rect2i::*;
57-
pub use rid::*;
58-
pub use signal::*;
61+
pub use rect2::Rect2;
62+
pub use rect2i::Rect2i;
63+
pub use rid::Rid;
64+
pub use signal::Signal;
5965
pub use string::{GString, NodePath, StringName};
60-
pub use transform2d::*;
61-
pub use transform3d::*;
62-
pub use variant::*;
63-
pub use vectors::*;
64-
66+
pub use transform2d::Transform2D;
67+
pub use transform3d::Transform3D;
68+
pub use variant::Variant;
69+
pub use vectors::{
70+
swizzle, ToVector, Vector2, Vector2Axis, Vector2i, Vector3, Vector3Axis, Vector3i,
71+
Vector4, Vector4Axis, Vector4i,
72+
};
73+
74+
pub use super::{EulerOrder, Side, VariantOperator, VariantType};
6575
pub use crate::{array, dict, real, reals, varray};
6676
}
6777

@@ -148,16 +158,14 @@ pub(crate) fn u8_to_bool(u: u8) -> bool {
148158
}
149159
}
150160

161+
// ----------------------------------------------------------------------------------------------------------------------------------------------
162+
// Deprecated enums
163+
151164
/// The side of a [`Rect2`] or [`Rect2i`].
152165
///
153166
/// _Godot equivalent: `@GlobalScope.Side`_
154-
#[deprecated(note = "Merged with `godot::global::Side`.")]
155-
pub type RectSide = crate::engine::global::Side;
156-
use crate::engine::global::Side;
157-
158-
/// The ordering used to interpret a set of euler angles as extrinsic rotations.
159-
#[deprecated(note = "Merged with `godot::global::EulerOrder`.")]
160-
pub type EulerOrder = crate::engine::global::EulerOrder;
167+
#[deprecated = "Merged with `godot::builtin::Side`."]
168+
pub type RectSide = Side;
161169

162170
#[allow(non_upper_case_globals)]
163171
impl Side {

godot-core/src/builtin/variant/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
*/
77

88
use crate::builtin::meta::{impl_godot_as_self, ArrayElement, ConvertError, FromGodot, ToGodot};
9-
use crate::builtin::{GString, StringName};
10-
use crate::gen::central::VariantDispatch;
9+
use crate::builtin::{GString, StringName, VariantDispatch, VariantOperator, VariantType};
1110
use godot_ffi as sys;
1211
use std::{fmt, ptr};
1312
use sys::{ffi_methods, interface_fn, GodotFfi};
1413

15-
pub use crate::engine::global::VariantOperator;
16-
pub use sys::VariantType;
17-
1814
mod impls;
1915

2016
/// Godot variant type, able to store a variety of different types.

0 commit comments

Comments
 (0)