Skip to content

Commit 654e4fc

Browse files
committed
- Fix array property export in godot 4.2
1 parent 139a251 commit 654e4fc

File tree

8 files changed

+68
-10
lines changed

8 files changed

+68
-10
lines changed

godot-core/src/builtin/array.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,14 @@ impl<T: GodotType> Property for Array<T> {
698698
fn set_property(&mut self, value: Self::Intermediate) {
699699
*self = value;
700700
}
701+
702+
#[cfg(since_api = "4.2")]
703+
fn property_hint() -> ExportInfo {
704+
ExportInfo {
705+
hint: crate::engine::global::PropertyHint::PROPERTY_HINT_ARRAY_TYPE,
706+
hint_string: T::godot_type_name().into(),
707+
}
708+
}
701709
}
702710

703711
impl<T: GodotType + TypeStringHint> Export for Array<T> {
@@ -753,6 +761,10 @@ impl<T: GodotType> GodotType for Array<T> {
753761
fn try_from_ffi(ffi: Self::Ffi) -> Option<Self> {
754762
Some(ffi)
755763
}
764+
765+
fn godot_type_name() -> String {
766+
"Array".into()
767+
}
756768
}
757769

758770
impl<T: GodotType> GodotFfiVariant for Array<T> {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ macro_rules! impl_godot_scalar {
118118
$param_metadata
119119
}
120120
)?
121+
122+
fn godot_type_name() -> String {
123+
<$Via as GodotType>::godot_type_name()
124+
}
121125
}
122126

123127
impl GodotConvert for $T {
@@ -158,6 +162,10 @@ macro_rules! impl_godot_scalar {
158162
$param_metadata
159163
}
160164
)?
165+
166+
fn godot_type_name() -> String {
167+
<$Via as GodotType>::godot_type_name()
168+
}
161169
}
162170

163171
impl GodotConvert for $T {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ pub trait GodotType: GodotConvert<Via = Self> + ToGodot + FromGodot + sealed::Se
164164
Self::param_metadata(),
165165
))
166166
}
167+
168+
#[doc(hidden)]
169+
fn godot_type_name() -> String;
167170
}
168171

169172
impl<T> GodotType for Option<T>
@@ -217,6 +220,10 @@ where
217220
fn return_info() -> Option<MethodParamOrReturnInfo> {
218221
T::return_info()
219222
}
223+
224+
fn godot_type_name() -> String {
225+
T::godot_type_name()
226+
}
220227
}
221228

222229
// ----------------------------------------------------------------------------------------------------------------------------------------------

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use sys::GodotFfi;
2121
//
2222
// Thus we can use `init` to indicate when it must be initialized in 4.0.
2323
macro_rules! impl_ffi_variant {
24-
($T:ty, $from_fn:ident, $to_fn:ident) => {
24+
($T:ty, $from_fn:ident, $to_fn:ident $(; $gd_ty:ident)?) => {
2525
impl GodotFfiVariant for $T {
2626
fn ffi_to_variant(&self) -> Variant {
2727
let variant = unsafe {
@@ -73,6 +73,20 @@ macro_rules! impl_ffi_variant {
7373
fn try_from_ffi(ffi: Self::Ffi) -> Option<Self> {
7474
Some(ffi)
7575
}
76+
77+
impl_ffi_variant!(@godot_type_name $T $(, $gd_ty)?);
78+
}
79+
};
80+
81+
(@godot_type_name $T:ty) => {
82+
fn godot_type_name() -> String {
83+
stringify!($T).into()
84+
}
85+
};
86+
87+
(@godot_type_name $T:ty, $gd_ty:ident) => {
88+
fn godot_type_name() -> String {
89+
stringify!($gd_ty).into()
7690
}
7791
};
7892
}
@@ -85,7 +99,7 @@ macro_rules! impl_ffi_variant {
8599
mod impls {
86100
use super::*;
87101

88-
impl_ffi_variant!(Aabb, aabb_to_variant, aabb_from_variant);
102+
impl_ffi_variant!(Aabb, aabb_to_variant, aabb_from_variant; AABB);
89103
impl_ffi_variant!(bool, bool_to_variant, bool_from_variant);
90104
impl_ffi_variant!(Basis, basis_to_variant, basis_from_variant);
91105
impl_ffi_variant!(Callable, callable_to_variant, callable_from_variant);
@@ -97,7 +111,7 @@ mod impls {
97111
impl_ffi_variant!(Vector4i, vector3i_to_variant, vector3i_from_variant);
98112
impl_ffi_variant!(Quaternion, quaternion_to_variant, quaternion_from_variant);
99113
impl_ffi_variant!(Color, color_to_variant, color_from_variant);
100-
impl_ffi_variant!(GodotString, string_to_variant, string_from_variant);
114+
impl_ffi_variant!(GodotString, string_to_variant, string_from_variant; String);
101115
impl_ffi_variant!(StringName, string_name_to_variant, string_name_from_variant);
102116
impl_ffi_variant!(NodePath, node_path_to_variant, node_path_from_variant);
103117
impl_ffi_variant!(PackedByteArray, packed_byte_array_to_variant, packed_byte_array_from_variant);
@@ -111,15 +125,15 @@ mod impls {
111125
impl_ffi_variant!(PackedColorArray, packed_color_array_to_variant, packed_color_array_from_variant);
112126
impl_ffi_variant!(Plane, plane_to_variant, plane_from_variant);
113127
impl_ffi_variant!(Projection, projection_to_variant, projection_from_variant);
114-
impl_ffi_variant!(Rid, rid_to_variant, rid_from_variant);
128+
impl_ffi_variant!(Rid, rid_to_variant, rid_from_variant; RID);
115129
impl_ffi_variant!(Rect2, rect2_to_variant, rect2_from_variant);
116130
impl_ffi_variant!(Rect2i, rect2i_to_variant, rect2i_from_variant);
117131
impl_ffi_variant!(Signal, signal_to_variant, signal_from_variant);
118132
impl_ffi_variant!(Transform2D, transform_2d_to_variant, transform_2d_from_variant);
119133
impl_ffi_variant!(Transform3D, transform_3d_to_variant, transform_3d_from_variant);
120134
impl_ffi_variant!(Dictionary, dictionary_to_variant, dictionary_from_variant);
121-
impl_ffi_variant!(i64, int_to_variant, int_from_variant);
122-
impl_ffi_variant!(f64, float_to_variant, float_from_variant);
135+
impl_ffi_variant!(i64, int_to_variant, int_from_variant; int);
136+
impl_ffi_variant!(f64, float_to_variant, float_from_variant; float);
123137

124138
}
125139

@@ -151,6 +165,10 @@ impl GodotType for () {
151165
fn try_from_ffi(_: Self::Ffi) -> Option<Self> {
152166
Some(())
153167
}
168+
169+
fn godot_type_name() -> String {
170+
"Variant".into()
171+
}
154172
}
155173

156174
impl GodotFfiVariant for Variant {
@@ -192,4 +210,8 @@ impl GodotType for Variant {
192210
fn param_metadata() -> sys::GDExtensionClassMethodArgumentMetadata {
193211
sys::GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT8
194212
}
213+
214+
fn godot_type_name() -> String {
215+
"Variant".into()
216+
}
195217
}

godot-core/src/obj/gd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ impl<T: GodotClass> GodotType for Gd<T> {
462462
fn class_name() -> crate::builtin::meta::ClassName {
463463
T::class_name()
464464
}
465+
466+
fn godot_type_name() -> String {
467+
T::class_name().to_string()
468+
}
465469
}
466470

467471
impl<T: GodotClass> Clone for Gd<T> {

godot-core/src/obj/raw.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ impl<T: GodotClass> GodotType for RawGd<T> {
516516
fn class_name() -> ClassName {
517517
T::class_name()
518518
}
519+
520+
fn godot_type_name() -> String {
521+
T::class_name().to_string()
522+
}
519523
}
520524

521525
impl<T: GodotClass> GodotFfiVariant for RawGd<T> {

godot-core/src/property.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use crate::engine::global::PropertyHint;
1616
pub trait Property {
1717
type Intermediate;
1818

19+
fn property_hint() -> ExportInfo {
20+
ExportInfo::with_hint_none()
21+
}
1922
fn get_property(&self) -> Self::Intermediate;
2023
fn set_property(&mut self, value: Self::Intermediate);
2124
}

godot-macros/src/class/data_models/property.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ pub fn make_property_impl(class_name: &Ident, fields: &Fields) -> TokenStream {
113113
} else {
114114
quote! {
115115
{
116-
(
117-
::godot::engine::global::PropertyHint::PROPERTY_HINT_NONE,
118-
::godot::builtin::GodotString::new()
119-
)
116+
let default_export_info = <#field_type as ::godot::bind::property::Property>::property_hint();
117+
(default_export_info.hint, default_export_info.hint_string)
120118
}
121119
}
122120
}

0 commit comments

Comments
 (0)