Skip to content

Commit

Permalink
PropertyInfo class_name should come from property object
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Aug 30, 2024
1 parent 6c732ad commit a42bbf6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
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
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

0 comments on commit a42bbf6

Please sign in to comment.