Skip to content

Commit 151d377

Browse files
authored
Upgrade to gdext 0.2.x (#59)
Fixes #58
1 parent ca371c1 commit 151d377

20 files changed

+531
-134
lines changed

Cargo.lock

Lines changed: 30 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ version = "0.1.0"
1010
edition = "2021"
1111

1212
[workspace.dependencies]
13-
godot = { git = "https://github.com/godot-rust/gdext", tag = "v0.1.3", features = ["experimental-threads"] }
14-
godot-cell = { git = "https://github.com/godot-rust/gdext", tag = "v0.1.3" }
15-
itertools = "0.10.3"
16-
rand = "0.8.5"
13+
godot = { version = "0.2", features = ["experimental-threads"] }
14+
godot-cell = "0.2"
15+
godot-bindings = "0.2"
16+
itertools = "0.10"
17+
rand = "0.8"
1718
darling = { version = "0.20" }
18-
proc-macro2 = "1.0.68"
19+
proc-macro2 = "1.0"
1920
quote = "1"
2021
syn = "2"
21-
const-str = "0.5.6"
22+
const-str = "0.5"
2223
thiserror = "1"
2324

2425
godot-rust-script-derive = { path = "derive" }

derive/src/enums.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ pub fn script_enum_derive(input: proc_macro::TokenStream) -> proc_macro::TokenSt
9393
}
9494

9595
impl #godot_types::meta::ToGodot for #enum_ident {
96+
type ToVia<'a> = Self::Via;
97+
9698
fn to_godot(&self) -> Self::Via {
9799
#enum_from_self::from(self)
98100
}

derive/src/impl_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn generate_public_interface(impl_body: &ItemImpl) -> TokenStream {
292292

293293
quote_spanned! { func.span() =>
294294
#func {
295-
(*self).call(#func_name.into(), &[#args]).to()
295+
(*self).call(#func_name, &[#args]).to()
296296
}
297297
}
298298
})

rust-script/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ thiserror.workspace = true
2121
tests-scripts-lib = { path = "../tests-scripts-lib" }
2222
godot-rust-script = { path = "./", features = ["runtime"] }
2323

24+
[build-dependencies]
25+
godot-bindings.workspace = true
26+
2427
[features]
2528
default = ["runtime", "scripts"]
2629
runtime = ["dep:itertools", "dep:rand"]

rust-script/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
fn main() {
8+
godot_bindings::emit_godot_version_cfg();
9+
}

rust-script/src/editor_ui_hacks.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,61 @@
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
55
*/
66

7-
use godot::engine::{EditorInterface, Engine};
8-
use godot::log::godot_warn;
7+
use godot::classes::{EditorInterface, Engine};
8+
use godot::global::godot_warn;
99
use godot::meta::ToGodot;
1010
use godot::prelude::GodotConvert;
1111

1212
#[derive(Clone, Copy)]
13-
pub enum EditorToaserSeverity {
13+
pub enum EditorToasterSeverity {
1414
Warning,
1515
}
1616

17-
impl From<EditorToaserSeverity> for u8 {
18-
fn from(value: EditorToaserSeverity) -> Self {
19-
use EditorToaserSeverity::*;
17+
impl From<EditorToasterSeverity> for u8 {
18+
fn from(value: EditorToasterSeverity) -> Self {
19+
use EditorToasterSeverity::*;
2020

2121
match value {
2222
Warning => 1,
2323
}
2424
}
2525
}
2626

27-
impl GodotConvert for EditorToaserSeverity {
27+
impl GodotConvert for EditorToasterSeverity {
2828
type Via = u8;
2929
}
3030

31-
impl ToGodot for EditorToaserSeverity {
32-
fn to_godot(&self) -> Self::Via {
31+
impl ToGodot for EditorToasterSeverity {
32+
type ToVia<'v> = Self::Via;
33+
34+
fn to_godot(&self) -> Self::ToVia<'static> {
3335
(*self).into()
3436
}
3537
}
3638

37-
pub fn show_editor_toast(message: &str, severity: EditorToaserSeverity) {
39+
pub fn show_editor_toast(message: &str, severity: EditorToasterSeverity) {
3840
if !Engine::singleton().is_editor_hint() {
3941
return;
4042
}
4143

44+
#[cfg(before_api = "4.2")]
45+
let Some(base_control) = Engine::singleton()
46+
.get_singleton("EditorInterface")
47+
.and_then(|obj| obj.cast::<EditorInterface>().get_base_control())
48+
else {
49+
godot_warn!("[godot-rust-script] unable to access editor UI!");
50+
return;
51+
};
52+
53+
#[cfg(since_api = "4.2")]
4254
let Some(base_control) = EditorInterface::singleton().get_base_control() else {
4355
godot_warn!("[godot-rust-script] unable to access editor UI!");
4456
return;
4557
};
4658

4759
let editor_toaser = base_control
48-
.find_children_ex("*".into())
49-
.type_("EditorToaster".into())
60+
.find_children_ex("*")
61+
.type_("EditorToaster")
5062
.recursive(true)
5163
.owned(false)
5264
.done()
@@ -57,13 +69,13 @@ pub fn show_editor_toast(message: &str, severity: EditorToaserSeverity) {
5769
return;
5870
};
5971

60-
if !editor_toaser.has_method("_popup_str".into()) {
72+
if !editor_toaser.has_method("_popup_str") {
6173
godot_warn!("[godot-rust-script] Internal toast notifications API no longer exists!");
6274
return;
6375
}
6476

6577
editor_toaser.call(
66-
"_popup_str".into(),
78+
"_popup_str",
6779
&[message.to_variant(), severity.to_variant(), "".to_variant()],
6880
);
6981
}

rust-script/src/interface/export.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use godot::builtin::{
1313
Rect2, Rect2i, Rid, StringName, Transform2D, Transform3D, Vector2, Vector2i, Vector3, Vector3i,
1414
Vector4, Vector4i,
1515
};
16-
use godot::engine::{Node, Resource};
16+
use godot::classes::{Node, Resource};
1717
use godot::global::PropertyHint;
1818
use godot::meta::{ArrayElement, FromGodot, GodotConvert, GodotType, ToGodot};
1919
use godot::obj::{EngineEnum, Gd};
@@ -32,7 +32,7 @@ impl<T: GodotClass> GodotScriptExport for Gd<T> {
3232
return custom;
3333
}
3434

35-
T::class_name().as_str().to_owned()
35+
T::class_name().to_string()
3636
}
3737

3838
fn hint(custom: Option<PropertyHint>) -> PropertyHint {
@@ -52,7 +52,11 @@ impl<T: GodotClass> GodotScriptExport for Gd<T> {
5252

5353
impl<T: GodotScriptExport> GodotScriptExport for Option<T>
5454
where
55+
for<'v> T: 'v,
56+
for<'v> <<T as ToGodot>::ToVia<'v> as GodotType>::Ffi: godot::sys::GodotNullableFfi,
57+
for<'f> <<T as GodotConvert>::Via as GodotType>::ToFfi<'f>: godot::sys::GodotNullableFfi,
5558
<<T as GodotConvert>::Via as GodotType>::Ffi: godot::sys::GodotNullableFfi,
59+
for<'v, 'f> <<T as ToGodot>::ToVia<'v> as GodotType>::ToFfi<'f>: godot::sys::GodotNullableFfi,
5660
{
5761
fn hint_string(custom_hint: Option<PropertyHint>, custom_string: Option<String>) -> String {
5862
T::hint_string(custom_hint, custom_string)
@@ -63,7 +67,7 @@ where
6367
}
6468
}
6569

66-
impl<T: ArrayElement + GodotScriptExport> GodotScriptExport for Array<T> {
70+
impl<T: ArrayElement + GodotScriptExport + GodotType> GodotScriptExport for Array<T> {
6771
fn hint_string(custom_hint: Option<PropertyHint>, custom_string: Option<String>) -> String {
6872
let element_type = <<T as GodotType>::Ffi as GodotFfi>::variant_type().ord();
6973
let element_hint = <T as GodotScriptExport>::hint(custom_hint).ord();

rust-script/src/interface/signals.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ impl<T: SignalArguments> ScriptSignal for Signal<T> {
160160
fn emit(&self, args: Self::Args) {
161161
self.host
162162
.clone()
163-
.emit_signal(StringName::from(self.name), &args.to_variants());
163+
.emit_signal(self.name, &args.to_variants());
164164
}
165165

166166
fn connect(&mut self, callable: Callable) -> Result<(), Error> {
167-
match self.host.connect(self.name.into(), callable) {
167+
match self.host.connect(self.name, &callable) {
168168
Error::OK => Ok(()),
169169
error => Err(error),
170170
}
@@ -184,6 +184,11 @@ impl<T: SignalArguments> GodotConvert for Signal<T> {
184184
}
185185

186186
impl<T: SignalArguments> ToGodot for Signal<T> {
187+
type ToVia<'v>
188+
= Self::Via
189+
where
190+
Self: 'v;
191+
187192
fn to_godot(&self) -> Self::Via {
188193
godot::builtin::Signal::from_object_signal(&self.host, self.name)
189194
}

rust-script/src/runtime/call_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ pub struct Context<'a, Script: GodotScriptImpl + ?Sized> {
2222
base_type: PhantomData<Script>,
2323
}
2424

25-
impl<'a, Script: GodotScriptImpl> Debug for Context<'a, Script> {
25+
impl<Script: GodotScriptImpl> Debug for Context<'_, Script> {
2626
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2727
f.write_str("Context { <Call Context> }")
2828
}
2929
}
3030

31-
impl<'a, Script: GodotScriptImpl> Context<'a, Script> {
31+
impl<Script: GodotScriptImpl> Context<'_, Script> {
3232
pub fn reentrant_scope<T: GodotScriptObject + 'static, Args, Return>(
3333
&mut self,
3434
self_ref: &mut T,

0 commit comments

Comments
 (0)