1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Expose _validate_property() for scripting

This commit is contained in:
kobewi
2023-04-07 14:01:57 +02:00
parent 713bfaf5ea
commit 67db4693eb
9 changed files with 111 additions and 2 deletions

View File

@@ -1728,6 +1728,25 @@ Variant::Type GDScriptInstance::get_property_type(const StringName &p_name, bool
return Variant::NIL;
}
void GDScriptInstance::validate_property(PropertyInfo &p_property) const {
Variant property = (Dictionary)p_property;
const Variant *args[1] = { &property };
const GDScript *sptr = script.ptr();
while (sptr) {
HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._validate_property);
if (E) {
Callable::CallError err;
Variant ret = E->value->call(const_cast<GDScriptInstance *>(this), args, 1, err);
if (err.error == Callable::CallError::CALL_OK) {
p_property = PropertyInfo::from_dict(property);
return;
}
}
sptr = sptr->_base;
}
}
void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
// exported members, not done yet!
@@ -1793,7 +1812,8 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
p_properties->push_back(sptr->get_class_category());
#endif // TOOLS_ENABLED
for (const PropertyInfo &prop : props) {
for (PropertyInfo &prop : props) {
validate_property(prop);
p_properties->push_back(prop);
}
@@ -2616,6 +2636,7 @@ GDScriptLanguage::GDScriptLanguage() {
strings._set = StaticCString::create("_set");
strings._get = StaticCString::create("_get");
strings._get_property_list = StaticCString::create("_get_property_list");
strings._validate_property = StaticCString::create("_validate_property");
strings._property_can_revert = StaticCString::create("_property_can_revert");
strings._property_get_revert = StaticCString::create("_property_get_revert");
strings._script_source = StaticCString::create("script/source");