-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Use the class_name for the field when building PropertyInfo #441
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,10 @@ | |
|
||
use godot::{ | ||
bind::property::ExportInfo, | ||
engine::{global::PropertyHint, Texture}, | ||
engine::{ | ||
global::{PropertyHint, PropertyUsageFlags}, | ||
Texture, | ||
}, | ||
prelude::*, | ||
test::itest, | ||
}; | ||
|
@@ -351,20 +354,101 @@ fn derive_export() { | |
.iter_shared() | ||
.find(|c| c.get_or_nil("name") == "foo".to_variant()) | ||
.unwrap(); | ||
assert_eq!( | ||
property.get_or_nil("class_name"), | ||
"DeriveExport".to_variant() | ||
// `class_name` should be empty for non-Object variants. | ||
check_property(&property, "class_name", ""); | ||
check_property(&property, "type", VariantType::Int as i32); | ||
check_property(&property, "hint", PropertyHint::PROPERTY_HINT_ENUM.ord()); | ||
check_property(&property, "hint_string", "A:0,B:1,C:2"); | ||
check_property( | ||
&property, | ||
"usage", | ||
PropertyUsageFlags::PROPERTY_USAGE_DEFAULT.ord(), | ||
); | ||
assert_eq!( | ||
property.get_or_nil("type"), | ||
(VariantType::Int as i32).to_variant() | ||
} | ||
|
||
#[derive(GodotClass)] | ||
#[class(init, base=Resource)] | ||
pub struct CustomResource {} | ||
|
||
#[godot_api] | ||
impl CustomResource {} | ||
|
||
#[godot_api] | ||
impl ResourceVirtual for CustomResource {} | ||
Comment on lines
+376
to
+377
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole (the inherent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat, when did that happen? Thought I was getting errors for not having that pretty recently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The inherent one is still needed, but not the trait one. |
||
|
||
#[derive(GodotClass)] | ||
#[class(init, base=Resource, rename=NewNameCustomResource)] | ||
pub struct RenamedCustomResource {} | ||
|
||
#[godot_api] | ||
impl RenamedCustomResource {} | ||
|
||
#[godot_api] | ||
impl ResourceVirtual for RenamedCustomResource {} | ||
|
||
#[derive(GodotClass)] | ||
#[class(init, base=Node)] | ||
pub struct ExportResource { | ||
#[export] | ||
#[var(usage_flags=[PROPERTY_USAGE_DEFAULT, PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT])] | ||
pub foo: Option<Gd<CustomResource>>, | ||
|
||
#[export] | ||
pub bar: Option<Gd<RenamedCustomResource>>, | ||
} | ||
|
||
#[godot_api] | ||
impl ExportResource {} | ||
|
||
#[godot_api] | ||
impl NodeVirtual for ExportResource {} | ||
|
||
#[itest] | ||
fn export_resource() { | ||
let class: Gd<ExportResource> = Gd::new_default(); | ||
|
||
let property = class | ||
.get_property_list() | ||
.iter_shared() | ||
.find(|c| c.get_or_nil("name") == "foo".to_variant()) | ||
.unwrap(); | ||
check_property(&property, "class_name", "CustomResource"); | ||
check_property(&property, "type", VariantType::Object as i32); | ||
check_property( | ||
&property, | ||
"hint", | ||
PropertyHint::PROPERTY_HINT_RESOURCE_TYPE.ord(), | ||
); | ||
check_property(&property, "hint_string", "CustomResource"); | ||
check_property( | ||
&property, | ||
"usage", | ||
PropertyUsageFlags::PROPERTY_USAGE_DEFAULT.ord() | ||
| PropertyUsageFlags::PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT.ord(), | ||
); | ||
assert_eq!( | ||
property.get_or_nil("hint"), | ||
(PropertyHint::PROPERTY_HINT_ENUM.ord()).to_variant() | ||
|
||
let property = class | ||
.get_property_list() | ||
.iter_shared() | ||
.find(|c| c.get_or_nil("name") == "bar".to_variant()) | ||
.unwrap(); | ||
check_property(&property, "class_name", "NewNameCustomResource"); | ||
check_property(&property, "type", VariantType::Object as i32); | ||
check_property( | ||
&property, | ||
"hint", | ||
PropertyHint::PROPERTY_HINT_RESOURCE_TYPE.ord(), | ||
); | ||
assert_eq!( | ||
property.get_or_nil("hint_string"), | ||
"A:0,B:1,C:2".to_variant() | ||
check_property(&property, "hint_string", "NewNameCustomResource"); | ||
check_property( | ||
&property, | ||
"usage", | ||
PropertyUsageFlags::PROPERTY_USAGE_DEFAULT.ord(), | ||
); | ||
|
||
class.free(); | ||
} | ||
|
||
fn check_property(property: &Dictionary, key: &str, expected: impl ToVariant) { | ||
assert_eq!(property.get_or_nil(key), expected.to_variant()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Clippy actually flagged the whole
PartialOrd
implementation as "incorrect" because there was an implementation forOrd
which was interesting.