-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "validate_property" virtual func
- Add validate_property func virtual. - Create internal API for easier handling of ``*mut GDExtensionPropertyInfo` - functions that allow to easily handle conversions from/to PropertyInfo and `borrow_string_sys_mut` for GString and StringName.
- Loading branch information
Showing
12 changed files
with
248 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) godot-rust; Bromeon and contributors. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
use godot::builtin::{Array, Dictionary, GString, StringName}; | ||
use godot::classes::IObject; | ||
use godot::global::{PropertyHint, PropertyUsageFlags}; | ||
use godot::meta::PropertyInfo; | ||
use godot::obj::NewAlloc; | ||
use godot::register::{godot_api, GodotClass}; | ||
use godot::test::itest; | ||
|
||
#[derive(GodotClass)] | ||
#[class(base = Object, init)] | ||
pub struct ValidatePropertyTest { | ||
#[var(hint = NONE, hint_string = "initial")] | ||
#[export] | ||
my_var: i64, | ||
} | ||
|
||
#[godot_api] | ||
impl IObject for ValidatePropertyTest { | ||
fn validate_property(&self, property: &mut PropertyInfo) { | ||
if property.property_name.to_string() == "my_var" { | ||
property.usage = PropertyUsageFlags::NO_EDITOR; | ||
property.property_name = StringName::from("SuperNewTestPropertyName"); | ||
property.hint_info.hint_string = GString::from("SomePropertyHint"); | ||
property.hint_info.hint = PropertyHint::TYPE_STRING; | ||
|
||
// Makes no sense but allows to check if given ClassName can be properly moved to GDExtensionPropertyInfo. | ||
property.class_name = <ValidatePropertyTest as godot::obj::GodotClass>::class_name(); | ||
} | ||
} | ||
} | ||
|
||
#[itest] | ||
fn validate_property_test() { | ||
let obj = ValidatePropertyTest::new_alloc(); | ||
let properties: Array<Dictionary> = obj.get_property_list(); | ||
|
||
for property in properties.iter_shared() { | ||
if !property | ||
.get("name") | ||
.is_some_and(|v| v.to_string() == "SuperNewTestPropertyName") | ||
{ | ||
continue; | ||
} | ||
|
||
let hint_string = property | ||
.get("hint_string") | ||
.map(|v| v.to::<GString>()) | ||
.expect("Validated property dict should contain a hint_string entry."); | ||
assert_eq!(hint_string, GString::from("SomePropertyHint")); | ||
|
||
let class = property | ||
.get("class_name") | ||
.map(|v| v.to::<StringName>()) | ||
.expect("Validated property dict should contain a class_name entry."); | ||
assert_eq!(class, StringName::from("ValidatePropertyTest")); | ||
|
||
let usage = property | ||
.get("usage") | ||
.map(|v| v.to::<PropertyUsageFlags>()) | ||
.expect("Validated property dict should contain an usage entry."); | ||
assert_eq!(usage, PropertyUsageFlags::NO_EDITOR); | ||
|
||
let hint = property | ||
.get("hint") | ||
.map(|v| v.to::<PropertyHint>()) | ||
.expect("Validated property dict should contain a hint entry."); | ||
assert_eq!(hint, PropertyHint::TYPE_STRING); | ||
|
||
obj.free(); | ||
return; | ||
} | ||
|
||
panic!("Test failed – unable to find validated property."); | ||
} |