Skip to content

Commit ce9abec

Browse files
committed
New module extras to combine GFile and other engine functionality
1 parent 4f9f47f commit ce9abec

File tree

12 files changed

+66
-40
lines changed

12 files changed

+66
-40
lines changed

godot-codegen/src/generator/notifications.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub fn make_notification_enum(
9797
///
9898
/// Makes it easier to keep an overview all possible notification variants for a given class, including
9999
/// notifications defined in base classes.
100+
///
101+
/// Contains the [`Unknown`] variant for forward compatibility.
100102
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
101103
#[repr(i32)]
102104
#cfg_attributes

godot-core/src/engine/mod.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,12 @@ use crate::obj::{bounds, Bounds, Gd, GodotClass, InstanceId};
1212

1313
// Re-exports of generated symbols
1414

15-
#[deprecated = "Enums have been moved to `godot::global`."]
16-
pub mod global {
17-
pub use crate::builtin::{Corner, EulerOrder, Side};
18-
pub use crate::global::*;
19-
}
20-
21-
#[deprecated = "Utility functions have been moved to `godot::global`."]
22-
pub mod utilities {
23-
pub use crate::global::*;
24-
}
25-
2615
pub use crate::gen::classes::*;
27-
pub use io::*;
2816
pub use script_instance::{create_script_instance, ScriptInstance, SiMut};
2917

3018
use crate::builtin::meta::CallContext;
3119
use crate::sys;
3220

33-
mod io;
3421
mod manual_extensions;
3522
mod script_instance;
3623
pub mod translate;
@@ -49,6 +36,38 @@ pub mod native {
4936
pub use crate::gen::native::*;
5037
}
5138

39+
// ----------------------------------------------------------------------------------------------------------------------------------------------
40+
// Deprecations
41+
42+
// #[deprecated = "Enums have been moved to `godot::global`."]
43+
// pub mod global {
44+
// pub use crate::builtin::{Corner, EulerOrder, Side};
45+
// pub use crate::global::*;
46+
// }
47+
//
48+
// #[deprecated = "Utility functions have been moved to `godot::global`."]
49+
// pub mod utilities {
50+
// pub use crate::global::*;
51+
// }
52+
//
53+
// #[deprecated = "`GFile` has been moved to `godot::extras`."]
54+
// pub use crate::extras::GFile;
55+
//
56+
// #[deprecated = "`IoError` has been moved to `godot::extras`."]
57+
// pub use crate::extras::IoError;
58+
//
59+
// #[deprecated = "`save` has been moved to `godot::global`."]
60+
// pub use crate::global::save;
61+
//
62+
// #[deprecated = "`try_save` has been moved to `godot::global`."]
63+
// pub use crate::global::try_save;
64+
//
65+
// #[deprecated = "`load` has been moved to `godot::global`."]
66+
// pub use crate::global::load;
67+
//
68+
// #[deprecated = "`try_load` has been moved to `godot::global`."]
69+
// pub use crate::global::try_load;
70+
5271
// ----------------------------------------------------------------------------------------------------------------------------------------------
5372
// Utilities for crate
5473

godot-core/src/engine/io/gfile.rs renamed to godot-core/src/extras/gfile.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
use crate::builtin::{real, GString, PackedByteArray, PackedStringArray, Variant};
99
use crate::engine::file_access::{CompressionMode, ModeFlags};
10-
use crate::gen::classes::FileAccess;
10+
use crate::engine::FileAccess;
11+
use crate::extras::IoError;
1112
use crate::global::Error;
1213
use crate::obj::Gd;
1314

14-
use crate::engine::io::IoError;
15-
1615
use std::cmp;
1716
use std::io::{BufRead, ErrorKind, Read, Seek, SeekFrom, Write};
1817

@@ -49,9 +48,9 @@ use std::io::{BufRead, ErrorKind, Read, Seek, SeekFrom, Write};
4948
/// ## Examples
5049
///
5150
/// ```no_run
52-
/// use godot::engine::GFile;
51+
/// use godot::builtin::GString;
5352
/// use godot::engine::file_access::ModeFlags;
54-
/// use godot::builtin::{GString};
53+
/// use godot::extras::GFile;
5554
///
5655
/// fn save_game() -> Result<(), std::io::Error> {
5756
///

godot-core/src/engine/io/io_error.rs renamed to godot-core/src/extras/io_error.rs

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

88
use std::error::Error;
99

10-
use crate::engine::global::Error as GodotError;
1110
use crate::gen::classes::FileAccess;
11+
use crate::global::Error as GodotError;
1212
use crate::obj::{Gd, NotUniqueError};
1313

1414
/// Error that can occur while using `gdext` IO utilities.

godot-core/src/engine/io/mod.rs renamed to godot-core/src/extras/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
mod gfile;
99
mod io_error;
10-
mod resources;
1110

12-
pub use gfile::GFile;
11+
pub use gfile::*;
1312
pub use io_error::*;
14-
pub use resources::{load, save, try_load, try_save};

godot-core/src/global/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
//! - Rectangle: [`Side`][crate::builtin::Side], [`Corner`][crate::builtin::Corner] <sub>(godot-generated)</sub>
2020
//! - Rotation: [`EulerOrder`][crate::builtin::EulerOrder] <sub>(godot-generated)</sub>
2121
//! - Variant: [`VariantType`][crate::builtin::VariantType], [`VariantOperator`][crate::builtin::VariantOperator]
22-
//! - Vector: [`Vector2Axis`](crate::builtin::Vector2Axis), [`Vector3Axis`](crate::builtin::Vector3Axis), [`Vector4Axis`](crate::builtin::Vector4Axis)
22+
//! - Vector: [`Vector2Axis`][crate::builtin::Vector2Axis], [`Vector3Axis`][crate::builtin::Vector3Axis], [`Vector4Axis`][crate::builtin::Vector4Axis]
2323
//!
2424
2525
mod print;
26+
mod save_load;
2627

2728
pub use crate::{godot_error, godot_print, godot_print_rich, godot_script_error, godot_warn};
2829

2930
// Some enums are directly re-exported from crate::builtin.
3031
pub use crate::gen::central::global_enums::*;
3132
pub use crate::gen::utilities::*;
33+
34+
pub use save_load::*;

godot-core/src/engine/io/resources.rs renamed to godot-core/src/global/save_load.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
*/
77

88
use crate::builtin::GString;
9-
use crate::engine::global::Error as GodotError;
10-
use crate::gen::classes::{Resource, ResourceLoader, ResourceSaver};
9+
use crate::engine::{Resource, ResourceLoader, ResourceSaver};
10+
use crate::extras::IoError;
11+
use crate::global::Error as GodotError;
1112
use crate::obj::{Gd, Inherits};
1213

13-
use super::IoError;
14-
1514
/// ⚠️ Loads a resource from the filesystem located at `path`, panicking on error.
1615
///
1716
/// See [`try_load`] for more information.

godot-core/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ pub use registry::*;
4040
/// * Enum/flag modules: `canvas_item`, etc.
4141
///
4242
/// Noteworthy sub-modules are:
43-
/// * [`notify`][crate::engine::notify]: all notification types, used when working with the virtual callback to handle lifecycle notifications.
44-
/// * [`global`][crate::engine::global]: global enums not belonging to a specific class.
45-
/// * [`utilities`][crate::engine::utilities]: utility methods that are global in Godot.
46-
/// * [`translate`][crate::engine::translate]: convenience macros for translation.
43+
/// * [`notify`][crate::engine::notify]: all notification enums, used when working with the virtual callback to handle lifecycle notifications.
44+
/// * [`native`][crate::engine::native]: definition of _native structure_ types.
4745
pub mod engine;
4846

47+
/// Higher-level additions to the Godot engine API.
48+
///
49+
/// Contains functionality that extends existing Godot classes and functions, to make them more versatile
50+
/// or better integrated with Rust.
51+
pub mod extras;
52+
4953
// Output of generated code. Mimics the file structure, symbols are re-exported.
5054
#[rustfmt::skip]
5155
#[allow(unused_imports, dead_code, non_upper_case_globals, non_snake_case)]

godot-core/src/registry/property.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use godot_ffi as sys;
1111

1212
use crate::builtin::meta::{FromGodot, GodotConvert, GodotType, ToGodot};
1313
use crate::builtin::GString;
14-
use crate::engine::global::PropertyHint;
14+
use crate::global::PropertyHint;
1515

1616
// ----------------------------------------------------------------------------------------------------------------------------------------------
1717
// Trait definitions
@@ -142,7 +142,7 @@ impl PropertyHintInfo {
142142
/// Each function is named the same as the equivalent Godot annotation. For instance `@export_range` in Godot is `fn export_range` here.
143143
pub mod export_info_functions {
144144
use crate::builtin::GString;
145-
use crate::engine::global::PropertyHint;
145+
use crate::global::PropertyHint;
146146

147147
use super::PropertyHintInfo;
148148

godot/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ const _: () = _validate_features();
223223
// Modules
224224

225225
#[doc(inline)]
226-
pub use godot_core::{builtin, engine, global, obj};
226+
pub use godot_core::{builtin, engine, extras, global, obj};
227227

228228
#[allow(deprecated)]
229229
pub use godot_core::log;

0 commit comments

Comments
 (0)