|
6 | 6 |
|
7 | 7 | use godot::{
|
8 | 8 | bind::property::ExportInfo,
|
9 |
| - engine::{global::PropertyHint, Texture}, |
| 9 | + engine::{ |
| 10 | + global::{PropertyHint, PropertyUsageFlags}, |
| 11 | + Texture, |
| 12 | + }, |
10 | 13 | prelude::*,
|
11 | 14 | test::itest,
|
12 | 15 | };
|
@@ -351,20 +354,101 @@ fn derive_export() {
|
351 | 354 | .iter_shared()
|
352 | 355 | .find(|c| c.get_or_nil("name") == "foo".to_variant())
|
353 | 356 | .unwrap();
|
354 |
| - assert_eq!( |
355 |
| - property.get_or_nil("class_name"), |
356 |
| - "DeriveExport".to_variant() |
| 357 | + // `class_name` should be empty for non-Object variants. |
| 358 | + check_property(&property, "class_name", ""); |
| 359 | + check_property(&property, "type", VariantType::Int as i32); |
| 360 | + check_property(&property, "hint", PropertyHint::PROPERTY_HINT_ENUM.ord()); |
| 361 | + check_property(&property, "hint_string", "A:0,B:1,C:2"); |
| 362 | + check_property( |
| 363 | + &property, |
| 364 | + "usage", |
| 365 | + PropertyUsageFlags::PROPERTY_USAGE_DEFAULT.ord(), |
357 | 366 | );
|
358 |
| - assert_eq!( |
359 |
| - property.get_or_nil("type"), |
360 |
| - (VariantType::Int as i32).to_variant() |
| 367 | +} |
| 368 | + |
| 369 | +#[derive(GodotClass)] |
| 370 | +#[class(init, base=Resource)] |
| 371 | +pub struct CustomResource {} |
| 372 | + |
| 373 | +#[godot_api] |
| 374 | +impl CustomResource {} |
| 375 | + |
| 376 | +#[godot_api] |
| 377 | +impl ResourceVirtual for CustomResource {} |
| 378 | + |
| 379 | +#[derive(GodotClass)] |
| 380 | +#[class(init, base=Resource, rename=NewNameCustomResource)] |
| 381 | +pub struct RenamedCustomResource {} |
| 382 | + |
| 383 | +#[godot_api] |
| 384 | +impl RenamedCustomResource {} |
| 385 | + |
| 386 | +#[godot_api] |
| 387 | +impl ResourceVirtual for RenamedCustomResource {} |
| 388 | + |
| 389 | +#[derive(GodotClass)] |
| 390 | +#[class(init, base=Node)] |
| 391 | +pub struct ExportResource { |
| 392 | + #[export] |
| 393 | + #[var(usage_flags=[PROPERTY_USAGE_DEFAULT, PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT])] |
| 394 | + pub foo: Option<Gd<CustomResource>>, |
| 395 | + |
| 396 | + #[export] |
| 397 | + pub bar: Option<Gd<RenamedCustomResource>>, |
| 398 | +} |
| 399 | + |
| 400 | +#[godot_api] |
| 401 | +impl ExportResource {} |
| 402 | + |
| 403 | +#[godot_api] |
| 404 | +impl NodeVirtual for ExportResource {} |
| 405 | + |
| 406 | +#[itest] |
| 407 | +fn export_resource() { |
| 408 | + let class: Gd<ExportResource> = Gd::new_default(); |
| 409 | + |
| 410 | + let property = class |
| 411 | + .get_property_list() |
| 412 | + .iter_shared() |
| 413 | + .find(|c| c.get_or_nil("name") == "foo".to_variant()) |
| 414 | + .unwrap(); |
| 415 | + check_property(&property, "class_name", "CustomResource"); |
| 416 | + check_property(&property, "type", VariantType::Object as i32); |
| 417 | + check_property( |
| 418 | + &property, |
| 419 | + "hint", |
| 420 | + PropertyHint::PROPERTY_HINT_RESOURCE_TYPE.ord(), |
| 421 | + ); |
| 422 | + check_property(&property, "hint_string", "CustomResource"); |
| 423 | + check_property( |
| 424 | + &property, |
| 425 | + "usage", |
| 426 | + PropertyUsageFlags::PROPERTY_USAGE_DEFAULT.ord() |
| 427 | + | PropertyUsageFlags::PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT.ord(), |
361 | 428 | );
|
362 |
| - assert_eq!( |
363 |
| - property.get_or_nil("hint"), |
364 |
| - (PropertyHint::PROPERTY_HINT_ENUM.ord()).to_variant() |
| 429 | + |
| 430 | + let property = class |
| 431 | + .get_property_list() |
| 432 | + .iter_shared() |
| 433 | + .find(|c| c.get_or_nil("name") == "bar".to_variant()) |
| 434 | + .unwrap(); |
| 435 | + check_property(&property, "class_name", "NewNameCustomResource"); |
| 436 | + check_property(&property, "type", VariantType::Object as i32); |
| 437 | + check_property( |
| 438 | + &property, |
| 439 | + "hint", |
| 440 | + PropertyHint::PROPERTY_HINT_RESOURCE_TYPE.ord(), |
365 | 441 | );
|
366 |
| - assert_eq!( |
367 |
| - property.get_or_nil("hint_string"), |
368 |
| - "A:0,B:1,C:2".to_variant() |
| 442 | + check_property(&property, "hint_string", "NewNameCustomResource"); |
| 443 | + check_property( |
| 444 | + &property, |
| 445 | + "usage", |
| 446 | + PropertyUsageFlags::PROPERTY_USAGE_DEFAULT.ord(), |
369 | 447 | );
|
| 448 | + |
| 449 | + class.free(); |
| 450 | +} |
| 451 | + |
| 452 | +fn check_property(property: &Dictionary, key: &str, expected: impl ToVariant) { |
| 453 | + assert_eq!(property.get_or_nil(key), expected.to_variant()); |
370 | 454 | }
|
0 commit comments