Skip to content

Commit

Permalink
Merge pull request #717 from lilizoey/fix/export-type-string
Browse files Browse the repository at this point in the history
Update type strings according to how godot 4.3 exports them currently
  • Loading branch information
Bromeon authored May 21, 2024
2 parents 27b0054 + f0537d5 commit a9a57a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 5 additions & 1 deletion godot-core/src/builtin/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,11 @@ impl<T: ArrayElement + TypeStringHint> TypeStringHint for Array<T> {

impl TypeStringHint for VariantArray {
fn type_string() -> String {
format!("{}:Array", VariantType::Array as i32)
if sys::GdextBuild::since_api("4.3") {
format!("{}:", VariantType::Array as i32)
} else {
format!("{}:Array", VariantType::Array as i32)
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion godot-core/src/builtin/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ impl Var for Dictionary {

impl TypeStringHint for Dictionary {
fn type_string() -> String {
format!("{}:Dictionary", sys::VariantType::Dictionary as i32)
if sys::GdextBuild::since_api("4.3") {
format!("{}:", sys::VariantType::Dictionary as i32)
} else {
format!("{}:Dictionary", sys::VariantType::Dictionary as i32)
}
}
}

Expand Down
25 changes: 19 additions & 6 deletions godot-core/src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

//! Registration support for property types.

use godot_ffi as sys;

use crate::builtin::meta::{FromGodot, GodotConvert, ToGodot};
use crate::builtin::GString;
use crate::engine::global::PropertyHint;
Expand Down Expand Up @@ -117,14 +119,20 @@ pub struct PropertyHintInfo {
}

impl PropertyHintInfo {
/// Create a new `PropertyHintInfo` with a property hint of
/// [`PROPERTY_HINT_NONE`](PropertyHint::NONE).
/// Create a new `PropertyHintInfo` with a property hint of [`PROPERTY_HINT_NONE`](PropertyHint::NONE).
///
/// Usually Godot expects this to be combined with a `hint_string` containing the name of the type.
/// Starting with Godot version 4.3, the hint string will always be the empty string. Before that, the hint string is set to
/// be `type_name`.
pub fn with_hint_none<S: Into<GString>>(type_name: S) -> Self {
let hint_string = if sys::GdextBuild::since_api("4.3") {
"".into()
} else {
type_name.into()
};

Self {
hint: PropertyHint::NONE,
hint_string: type_name.into(),
hint_string,
}
}
}
Expand Down Expand Up @@ -367,8 +375,13 @@ mod export_impls {
fn type_string() -> String {
use sys::GodotFfi as _;
let variant_type = <$Ty as $crate::builtin::meta::GodotType>::Ffi::variant_type();
let type_name = <$Ty as $crate::builtin::meta::GodotType>::godot_type_name();
format!("{}:{}", variant_type as i32, type_name)

if sys::GdextBuild::since_api("4.3") {
format!("{}:", variant_type as i32)
} else {
let type_name = <$Ty as $crate::builtin::meta::GodotType>::godot_type_name();
format!("{}:{}", variant_type as i32, type_name)
}
}
}
}
Expand Down

0 comments on commit a9a57a5

Please sign in to comment.