Skip to content

Commit c9c2793

Browse files
committed
Merge pull request #460 from lilizoey/fix/type-string-hint-impls
Add missing `TypeStringHint` impls for all relevant types
2 parents 43f5d2f + 43439ac commit c9c2793

File tree

21 files changed

+529
-96
lines changed

21 files changed

+529
-96
lines changed

.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
15
# These are supported funding model platforms
26

37
# Up to 4 GitHub Sponsors usernames

godot-core/src/builtin/array.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use godot_ffi as sys;
88

99
use crate::builtin::*;
1010
use crate::obj::Share;
11-
use crate::property::{Export, ExportInfo, Property, TypeStringHint};
11+
use crate::property::{Export, Property, PropertyHintInfo, TypeStringHint};
1212
use std::fmt;
1313
use std::marker::PhantomData;
1414
use sys::{ffi_methods, interface_fn, GodotFfi};
@@ -682,6 +682,12 @@ impl<T: GodotType + TypeStringHint> TypeStringHint for Array<T> {
682682
}
683683
}
684684

685+
impl TypeStringHint for VariantArray {
686+
fn type_string() -> String {
687+
format!("{}:Array", VariantType::Array as i32)
688+
}
689+
}
690+
685691
impl<T: GodotType> Property for Array<T> {
686692
type Intermediate = Self;
687693

@@ -692,20 +698,32 @@ impl<T: GodotType> Property for Array<T> {
692698
fn set_property(&mut self, value: Self::Intermediate) {
693699
*self = value;
694700
}
701+
702+
#[cfg(since_api = "4.2")]
703+
fn property_hint() -> PropertyHintInfo {
704+
if T::Ffi::variant_type() == VariantType::Nil {
705+
return PropertyHintInfo::with_hint_none("");
706+
}
707+
708+
PropertyHintInfo {
709+
hint: crate::engine::global::PropertyHint::PROPERTY_HINT_ARRAY_TYPE,
710+
hint_string: T::godot_type_name().into(),
711+
}
712+
}
695713
}
696714

697715
impl<T: GodotType + TypeStringHint> Export for Array<T> {
698-
fn default_export_info() -> ExportInfo {
699-
ExportInfo {
716+
fn default_export_info() -> PropertyHintInfo {
717+
PropertyHintInfo {
700718
hint: crate::engine::global::PropertyHint::PROPERTY_HINT_TYPE_STRING,
701719
hint_string: T::type_string().into(),
702720
}
703721
}
704722
}
705723

706724
impl Export for Array<Variant> {
707-
fn default_export_info() -> ExportInfo {
708-
ExportInfo::with_hint_none()
725+
fn default_export_info() -> PropertyHintInfo {
726+
PropertyHintInfo::with_hint_none("Array")
709727
}
710728
}
711729

@@ -747,6 +765,10 @@ impl<T: GodotType> GodotType for Array<T> {
747765
fn try_from_ffi(ffi: Self::Ffi) -> Option<Self> {
748766
Some(ffi)
749767
}
768+
769+
fn godot_type_name() -> String {
770+
"Array".into()
771+
}
750772
}
751773

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

godot-core/src/builtin/dictionary.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use godot_ffi as sys;
99
use crate::builtin::meta::{FromGodot, ToGodot};
1010
use crate::builtin::{inner, Variant};
1111
use crate::obj::Share;
12-
use crate::property::{Export, ExportInfo, Property};
12+
use crate::property::{Export, Property, PropertyHintInfo, TypeStringHint};
1313
use std::fmt;
1414
use std::marker::PhantomData;
1515
use std::ptr::addr_of_mut;
1616
use sys::types::OpaqueDictionary;
17-
use sys::{ffi_methods, interface_fn, AsUninit, GodotFfi};
17+
use sys::{ffi_methods, interface_fn, AsUninit, GodotFfi, VariantType};
1818

1919
use super::meta::impl_godot_as_self;
2020
use super::VariantArray;
@@ -344,9 +344,15 @@ impl Property for Dictionary {
344344
}
345345
}
346346

347+
impl TypeStringHint for Dictionary {
348+
fn type_string() -> String {
349+
format!("{}:Dictionary", VariantType::Dictionary as i32)
350+
}
351+
}
352+
347353
impl Export for Dictionary {
348-
fn default_export_info() -> ExportInfo {
349-
ExportInfo::with_hint_none()
354+
fn default_export_info() -> PropertyHintInfo {
355+
PropertyHintInfo::with_hint_none("Dictionary")
350356
}
351357
}
352358

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: 29 additions & 7 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 $(; $godot_type_name: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 $(, $godot_type_name)?);
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, $godot_type_name:ident) => {
88+
fn godot_type_name() -> String {
89+
stringify!($godot_type_name).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);
@@ -94,10 +108,10 @@ mod impls {
94108
impl_ffi_variant!(Vector4, vector4_to_variant, vector4_from_variant);
95109
impl_ffi_variant!(Vector2i, vector2i_to_variant, vector2i_from_variant);
96110
impl_ffi_variant!(Vector3i, vector3i_to_variant, vector3i_from_variant);
97-
impl_ffi_variant!(Vector4i, vector3i_to_variant, vector3i_from_variant);
111+
impl_ffi_variant!(Vector4i, vector4i_to_variant, vector4i_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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::builtin::meta::{FromGodot, GodotConvert, GodotType, ToGodot};
1616
use crate::builtin::{Callable, StringName};
1717
use crate::obj::{cap, dom, mem, EngineEnum, GdDerefTarget, GodotClass, Inherits, Share};
1818
use crate::obj::{GdMut, GdRef, InstanceId};
19-
use crate::property::{Export, ExportInfo, Property, TypeStringHint};
19+
use crate::property::{Export, Property, PropertyHintInfo, TypeStringHint};
2020
use crate::{callbacks, engine, out};
2121

2222
use super::RawGd;
@@ -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> {
@@ -509,7 +513,7 @@ impl<T: GodotClass> Property for Gd<T> {
509513
}
510514

511515
impl<T: GodotClass> Export for Gd<T> {
512-
fn default_export_info() -> ExportInfo {
516+
fn default_export_info() -> PropertyHintInfo {
513517
let hint = if T::inherits::<engine::Resource>() {
514518
engine::global::PropertyHint::PROPERTY_HINT_RESOURCE_TYPE
515519
} else if T::inherits::<engine::Node>() {
@@ -522,7 +526,7 @@ impl<T: GodotClass> Export for Gd<T> {
522526
// but doesn't seem to make a difference otherwise.
523527
let hint_string = T::class_name().to_godot_string();
524528

525-
ExportInfo { hint, hint_string }
529+
PropertyHintInfo { hint, hint_string }
526530
}
527531
}
528532

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> {

0 commit comments

Comments
 (0)