Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PropertyInfo class_name should come from property object #57

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions derive/src/impl_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn godot_script_impl(
.enumerate()
.map(|(index, arg)| {
let arg_name = arg.pat.as_ref();
let arg_rust_type = arg.ty.as_ref();
let arg_type = rust_to_variant_type(arg.ty.as_ref()).unwrap();

is_context_type(arg.ty.as_ref()).then(|| {
Expand All @@ -72,6 +73,7 @@ pub fn godot_script_impl(
::godot_rust_script::private_export::RustScriptPropDesc {
name: stringify!(#arg_name),
ty: #arg_type,
class_name: <<#arg_rust_type as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
exported: false,
hint: #property_hints::NONE,
hint_string: String::new(),
Expand Down Expand Up @@ -132,6 +134,7 @@ pub fn godot_script_impl(
return_type: ::godot_rust_script::private_export::RustScriptPropDesc {
name: #fn_name_str,
ty: #fn_return_ty,
class_name: <<#fn_return_ty_rust as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
exported: false,
hint: #property_hints::NONE,
hint_string: String::new(),
Expand Down
3 changes: 3 additions & 0 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,15 @@ fn derive_field_metadata(
field: &SpannedValue<FieldOpts>,
is_exported: bool,
) -> Result<TokenStream, TokenStream> {
let godot_types = godot_types();
let property_hint_ty = property_hints();
let name = field
.ident
.as_ref()
.map(|field| field.to_string())
.unwrap_or_default();

let rust_ty = &field.ty;
let ty = rust_to_variant_type(&field.ty)?;

let (hint, hint_string) = is_exported
Expand All @@ -401,6 +403,7 @@ fn derive_field_metadata(
::godot_rust_script::private_export::RustScriptPropDesc {
name: #name,
ty: #ty,
class_name: <<#rust_ty as #godot_types::meta::GodotConvert>::Via as #godot_types::meta::GodotType>::class_name(),
exported: #is_exported,
hint: #hint,
hint_string: #hint_string,
Expand Down
1 change: 1 addition & 0 deletions rust-script/src/interface/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ macro_rules! signal_argument_desc {
RustScriptPropDesc {
name: $name,
ty: <<<$type as GodotConvert>::Via as GodotType>::Ffi as godot::sys::GodotFfi>::variant_type(),
class_name: <<$type as GodotConvert>::Via as GodotType>::class_name(),
exported: false,
hint: PropertyHint::NONE,
hint_string: String::new(),
Expand Down
15 changes: 11 additions & 4 deletions rust-script/src/runtime/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::ops::Deref;

use godot::meta::{MethodInfo, PropertyInfo};
use godot::meta::{ClassName, MethodInfo, PropertyInfo};
use godot::obj::{EngineBitfield, EngineEnum};
use godot::prelude::{Array, Dictionary};
use godot::sys::VariantType;
Expand Down Expand Up @@ -93,6 +93,13 @@ fn variant_type_to_str(var_type: VariantType) -> &'static str {
}
}

fn prop_doc_type(prop_type: VariantType, class_name: ClassName) -> &'static str {
match prop_type {
VariantType::OBJECT => class_name.as_str(),
_ => variant_type_to_str(prop_type),
}
}

pub trait ToMethodDoc {
fn to_method_doc(&self) -> Dictionary;
}
Expand All @@ -109,7 +116,7 @@ impl ToMethodDoc for MethodInfo {
dict.set("name", self.method_name.clone());
dict.set(
"return_type",
variant_type_to_str(self.return_type.variant_type),
prop_doc_type(self.return_type.variant_type, self.return_type.class_name),
);
dict.set("is_deprecated", false);
dict.set("is_experimental", false);
Expand Down Expand Up @@ -184,7 +191,7 @@ impl ToArgumentDoc for PropertyInfo {
fn to_argument_doc(&self) -> Dictionary {
Dictionary::new().apply(|dict| {
dict.set("name", self.property_name.clone());
dict.set("type", variant_type_to_str(self.variant_type));
dict.set("type", prop_doc_type(self.variant_type, self.class_name));
})
}
}
Expand All @@ -205,7 +212,7 @@ impl ToPropertyDoc for PropertyInfo {
fn to_property_doc(&self) -> Dictionary {
Dictionary::new().apply(|dict| {
dict.set("name", self.property_name.clone());
dict.set("type", variant_type_to_str(self.variant_type));
dict.set("type", prop_doc_type(self.variant_type, self.class_name));
dict.set("is_deprecated", false);
dict.set("is_experimental", false);
})
Expand Down
17 changes: 9 additions & 8 deletions rust-script/src/static_script_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ pub enum RegistryItem {
pub struct RustScriptPropDesc {
pub name: &'static str,
pub ty: VariantType,
pub class_name: ClassName,
pub exported: bool,
pub hint: PropertyHint,
pub hint_string: String,
pub description: &'static str,
}

impl RustScriptPropDesc {
pub fn to_property_info(&self, class_name: &'static str) -> RustScriptPropertyInfo {
pub fn to_property_info(&self) -> RustScriptPropertyInfo {
RustScriptPropertyInfo {
variant_type: self.ty,
class_name,
class_name: self.class_name,
property_name: self.name,
usage: if self.exported {
(PropertyUsageFlags::EDITOR | PropertyUsageFlags::STORAGE).ord()
Expand Down Expand Up @@ -118,12 +119,12 @@ impl RustScriptMethodDesc {
id,
method_name: self.name,
class_name,
return_type: self.return_type.to_property_info(class_name),
return_type: self.return_type.to_property_info(),
flags: self.flags.ord(),
arguments: self
.arguments
.iter()
.map(|arg| arg.to_property_info(class_name))
.map(|arg| arg.to_property_info())
.collect(),
description: self.description,
}
Expand All @@ -143,7 +144,7 @@ impl From<RustScriptSignalDesc> for RustScriptSignalInfo {
arguments: value
.arguments
.iter()
.map(|arg| arg.to_property_info("\0"))
.map(|arg| arg.to_property_info())
.collect(),
description: value.description,
}
Expand Down Expand Up @@ -174,7 +175,7 @@ pub fn assemble_metadata<'a>(
.map(|class| {
let props = (class.properties)()
.into_iter()
.map(|prop| prop.to_property_info(class.class_name))
.map(|prop| prop.to_property_info())
.collect();

let methods = methods
Expand Down Expand Up @@ -210,7 +211,7 @@ pub fn assemble_metadata<'a>(
pub struct RustScriptPropertyInfo {
pub variant_type: VariantType,
pub property_name: &'static str,
pub class_name: &'static str,
pub class_name: ClassName,
pub hint: i32,
pub hint_string: String,
pub usage: u64,
Expand All @@ -222,7 +223,7 @@ impl From<&RustScriptPropertyInfo> for PropertyInfo {
Self {
variant_type: value.variant_type,
property_name: value.property_name.into(),
class_name: ClassName::from_ascii_cstr(value.class_name.as_bytes()),
class_name: value.class_name,
hint: PropertyHint::try_from_ord(value.hint).unwrap_or(PropertyHint::NONE),
hint_string: value.hint_string.to_godot(),
usage: PropertyUsageFlags::try_from_ord(value.usage)
Expand Down
Loading