Skip to content

Commit 3ada98d

Browse files
authored
Migrate to godot-rust 0.4 (#80)
1 parent 1c0d080 commit 3ada98d

20 files changed

+126
-151
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
RUSTFLAGS: "-D warnings"
2020
strategy:
2121
matrix:
22-
api_version: ["4-1", "4-2", "4-3", "4-4"]
22+
api_version: ["4-2", "4-3", "4-4", "4-5"]
2323

2424
steps:
2525
- name: Checkout
@@ -49,7 +49,7 @@ jobs:
4949
runs-on: "ubuntu-22.04"
5050
strategy:
5151
matrix:
52-
api_version: ["4-1", "4-2", "4-3", "4-4"]
52+
api_version: ["4-2", "4-3", "4-4", "4-5"]
5353

5454
steps:
5555
- name: Checkout
@@ -75,7 +75,7 @@ jobs:
7575
runs-on: "ubuntu-22.04"
7676
strategy:
7777
matrix:
78-
api_version: ["4-1", "4-2", "4-3", "4-4", "custom"]
78+
api_version: ["4-2", "4-3", "4-4", "4-5", "custom"]
7979

8080
steps:
8181
- name: Checkout

.github/workflows/nightly-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
RUSTFLAGS: "-D warnings"
1717
strategy:
1818
matrix:
19-
api_version: ["4-1", "4-2", "4-3", "4-4"]
19+
api_version: ["4-2", "4-3", "4-4", "4-5"]
2020

2121
steps:
2222
- name: Checkout

Cargo.lock

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

Cargo.toml

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

1212
[workspace.dependencies]
13-
godot = { version = "0.3.2", features = ["experimental-threads"] }
14-
godot-cell = "0.3"
15-
godot-bindings = "0.3"
13+
godot = { version = ">=0.4.1", features = ["experimental-threads"] }
14+
godot-cell = "0.4.0"
15+
godot-bindings = "0.4.0"
1616
itertools = "0.10"
1717
rand = "0.8"
1818
darling = { version = "0.20" }

derive/src/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ 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;
96+
type Pass = ::godot::meta::ByValue;
9797

9898
fn to_godot(&self) -> Self::Via {
9999
#enum_from_self::from(self)

derive/src/impl_attribute.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn godot_script_impl(
2525
let godot_types = godot_types();
2626
let string_name_ty = string_name_ty();
2727
let variant_ty = variant_ty();
28-
let call_error_ty = quote!(#godot_types::sys::GDExtensionCallErrorType);
28+
let call_error_ty = quote!(#godot_types::meta::error::CallErrorType);
2929
let property_hints = property_hints();
3030

3131
let current_type = &body.self_ty;
@@ -73,7 +73,7 @@ pub fn godot_script_impl(
7373
::godot_rust_script::private_export::RustScriptPropDesc {
7474
name: stringify!(#arg_name),
7575
ty: #arg_type,
76-
class_name: <<#arg_rust_type as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
76+
class_name: <<#arg_rust_type as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_id(),
7777
exported: false,
7878
hint: #property_hints::NONE,
7979
hint_string: String::new(),
@@ -84,10 +84,10 @@ pub fn godot_script_impl(
8484
quote_spanned! {
8585
arg.span() =>
8686
#godot_types::prelude::FromGodot::try_from_variant(
87-
args.get(#index).ok_or(#godot_types::sys::GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS)?
87+
args.get(#index).ok_or(#call_error_ty::TooFewArguments)?
8888
).map_err(|err| {
8989
#godot_types::global::godot_error!("failed to convert variant for argument {} of {}: {}", stringify!(#arg_name), #fn_name_str, err);
90-
#godot_types::sys::GDEXTENSION_CALL_ERROR_INVALID_ARGUMENT
90+
#call_error_ty::InvalidArgument
9191
})?,
9292
}
9393
)
@@ -104,7 +104,7 @@ pub fn godot_script_impl(
104104
fnc.span() =>
105105
#fn_name_str => {
106106
if args.len() > #arg_count {
107-
return Err(#godot_types::sys::GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS);
107+
return Err(#call_error_ty::TooManyArguments);
108108
}
109109

110110
Ok(#godot_types::prelude::ToGodot::to_variant(&self.#fn_name(#args)))
@@ -134,7 +134,7 @@ pub fn godot_script_impl(
134134
return_type: ::godot_rust_script::private_export::RustScriptPropDesc {
135135
name: #fn_name_str,
136136
ty: #fn_return_ty,
137-
class_name: <<#fn_return_ty_rust as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
137+
class_name: <<#fn_return_ty_rust as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_id(),
138138
exported: false,
139139
hint: #property_hints::NONE,
140140
hint_string: String::new(),
@@ -164,7 +164,7 @@ pub fn godot_script_impl(
164164
match name.to_string().as_str() {
165165
#method_dispatch
166166

167-
_ => Err(#godot_types::sys::GDEXTENSION_CALL_ERROR_INVALID_METHOD),
167+
_ => Err(#call_error_ty::InvalidMethod),
168168
}
169169
}
170170
}

derive/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
2828
let godot_types = godot_types();
2929
let variant_ty = variant_ty();
3030
let string_name_ty = string_name_ty();
31-
let call_error_ty = quote!(#godot_types::sys::GDExtensionCallErrorType);
31+
let call_error_ty = quote!(#godot_types::meta::error::CallErrorType);
3232

3333
let base_class = opts
3434
.base
@@ -409,7 +409,7 @@ fn derive_field_metadata(
409409
::godot_rust_script::private_export::RustScriptPropDesc {
410410
name: #name,
411411
ty: #ty,
412-
class_name: <<#rust_ty as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
412+
class_name: <<#rust_ty as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_id(),
413413
exported: #is_exported,
414414
hint: #hint,
415415
hint_string: #hint_string,

rust-script/src/editor_ui_hacks.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
use godot::classes::{EditorInterface, Engine};
88
use godot::global::godot_warn;
9-
use godot::meta::ToGodot;
9+
use godot::meta::{ByValue, ToGodot};
10+
use godot::obj::Singleton as _;
1011
use godot::prelude::GodotConvert;
1112

1213
#[derive(Clone, Copy)]
@@ -29,9 +30,9 @@ impl GodotConvert for EditorToasterSeverity {
2930
}
3031

3132
impl ToGodot for EditorToasterSeverity {
32-
type ToVia<'v> = Self::Via;
33+
type Pass = ByValue;
3334

34-
fn to_godot(&self) -> Self::ToVia<'static> {
35+
fn to_godot(&self) -> Self::Via {
3536
(*self).into()
3637
}
3738
}

rust-script/src/interface.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ use std::marker::PhantomData;
1212
use std::ops::{Deref, DerefMut};
1313
use std::{collections::HashMap, fmt::Debug};
1414

15-
use godot::meta::{FromGodot, GodotConvert, ToGodot};
15+
use godot::meta::error::CallErrorType;
16+
use godot::meta::{ByValue, FromGodot, GodotConvert, ToGodot};
1617
use godot::obj::Inherits;
1718
use godot::prelude::{ConvertError, Gd, Object, StringName, Variant};
1819

1920
pub use crate::runtime::Context;
21+
use crate::runtime::RustScript;
2022

2123
pub use export::GodotScriptExport;
2224
pub use on_editor::OnEditor;
@@ -35,7 +37,7 @@ pub trait GodotScript: Debug + GodotScriptImpl<ImplBase = Self::Base> {
3537
method: StringName,
3638
args: &[&Variant],
3739
context: Context<'_, Self>,
38-
) -> Result<Variant, godot::sys::GDExtensionCallErrorType>;
40+
) -> Result<Variant, CallErrorType>;
3941

4042
fn to_string(&self) -> String;
4143
fn property_state(&self) -> HashMap<StringName, Variant>;
@@ -51,7 +53,7 @@ pub trait GodotScriptImpl {
5153
name: StringName,
5254
args: &[&Variant],
5355
context: Context<Self>,
54-
) -> Result<Variant, godot::sys::GDExtensionCallErrorType>;
56+
) -> Result<Variant, godot::meta::error::CallErrorType>;
5557
}
5658

5759
#[derive(Debug)]
@@ -72,7 +74,8 @@ impl<T: GodotScript> RsRef<T> {
7274
let script = owner
7375
.upcast_ref::<Object>()
7476
.get_script()
75-
.try_to::<Option<Gd<crate::runtime::RustScript>>>();
77+
.map(|script| script.try_cast::<RustScript>())
78+
.transpose();
7679

7780
let Ok(script) = script else {
7881
return Some(GodotScriptCastError::NotRustScript);
@@ -127,20 +130,16 @@ where
127130
}
128131

129132
impl<T: GodotScript> ToGodot for RsRef<T> {
130-
type ToVia<'v>
131-
= Gd<T::Base>
132-
where
133-
Self: 'v;
133+
type Pass = ByValue;
134134

135-
fn to_godot(&self) -> Self::ToVia<'_> {
135+
fn to_godot(&self) -> Self::Via {
136136
self.deref().clone()
137137
}
138138
}
139139

140-
impl<'v, T: GodotScript> ::godot::prelude::Var for RsRef<T>
140+
impl<T: GodotScript> ::godot::prelude::Var for RsRef<T>
141141
where
142-
Self: GodotConvert<Via = <Self as ToGodot>::ToVia<'v>>,
143-
Self: 'v,
142+
Self: GodotConvert,
144143
{
145144
fn get_property(&self) -> Self::Via {
146145
<Self as ToGodot>::to_godot(self)
@@ -193,7 +192,7 @@ impl<T: GodotScript, B: Inherits<T::Base> + Inherits<Object>> CastToScript<T> fo
193192
self.try_to_script().unwrap_or_else(|err| {
194193
panic!(
195194
"`{}` was assumed to have rust script `{}`, but this was not the case at runtime!\nError: {}",
196-
B::class_name(),
195+
B::class_id(),
197196
T::CLASS_NAME,
198197
err,
199198
);
@@ -204,7 +203,7 @@ impl<T: GodotScript, B: Inherits<T::Base> + Inherits<Object>> CastToScript<T> fo
204203
self.try_into_script().unwrap_or_else(|err| {
205204
panic!(
206205
"`{}` was assumed to have rust script `{}`, but this was not the case at runtime!\nError: {}",
207-
B::class_name(),
206+
B::class_id(),
208207
T::CLASS_NAME,
209208
err
210209
);

rust-script/src/interface/export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<T: GodotClass> GodotScriptExport for Gd<T> {
3535
return custom;
3636
}
3737

38-
T::class_name().to_string()
38+
T::class_id().to_string()
3939
}
4040

4141
fn hint(custom: Option<PropertyHint>) -> PropertyHint {

0 commit comments

Comments
 (0)