summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-04-07 14:01:57 +0200
committerkobewi <kobewi4e@gmail.com>2023-08-28 15:18:48 +0200
commit67db4693ebdc972eae2395fecd39dc174045b980 (patch)
tree54bd2a4097fd2b744459e45f3f14a66895a46cb2 /modules
parent713bfaf5eac1eb8a770e5ee825db29de99f3d0f7 (diff)
downloadredot-engine-67db4693ebdc972eae2395fecd39dc174045b980.tar.gz
Expose _validate_property() for scripting
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript.cpp23
-rw-r--r--modules/gdscript/gdscript.h2
-rw-r--r--modules/mono/csharp_script.cpp21
-rw-r--r--modules/mono/csharp_script.h1
4 files changed, 45 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 42b08f8a68..eda170bf80 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -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");
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index c41b1a0def..c6142dc10b 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -319,6 +319,7 @@ public:
virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
+ virtual void validate_property(PropertyInfo &p_property) const;
virtual bool property_can_revert(const StringName &p_name) const;
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const;
@@ -466,6 +467,7 @@ public:
StringName _set;
StringName _get;
StringName _get_property_list;
+ StringName _validate_property;
StringName _property_can_revert;
StringName _property_get_revert;
StringName _script_source;
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 2971706c75..1fcb2791d9 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -1656,7 +1656,8 @@ void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const {
}
}
- for (const PropertyInfo &prop : props) {
+ for (PropertyInfo &prop : props) {
+ validate_property(prop);
p_properties->push_back(prop);
}
}
@@ -1694,6 +1695,24 @@ bool CSharpInstance::property_can_revert(const StringName &p_name) const {
return (bool)ret;
}
+void CSharpInstance::validate_property(PropertyInfo &p_property) const {
+ ERR_FAIL_COND(!script.is_valid());
+
+ Variant property_arg = (Dictionary)p_property;
+ const Variant *args[1] = { &property_arg };
+
+ Variant ret;
+ Callable::CallError call_error;
+ GDMonoCache::managed_callbacks.CSharpInstanceBridge_Call(
+ gchandle.get_intptr(), &SNAME("_validate_property"), args, 1, &call_error, &ret);
+
+ if (call_error.error != Callable::CallError::CALL_OK) {
+ return;
+ }
+
+ p_property = PropertyInfo::from_dict(property_arg);
+}
+
bool CSharpInstance::property_get_revert(const StringName &p_name, Variant &r_ret) const {
ERR_FAIL_COND_V(!script.is_valid(), false);
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index 9802067b46..d089eca2f6 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -255,6 +255,7 @@ public:
bool get(const StringName &p_name, Variant &r_ret) const override;
void get_property_list(List<PropertyInfo> *p_properties) const override;
Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override;
+ virtual void validate_property(PropertyInfo &p_property) const override;
bool property_can_revert(const StringName &p_name) const override;
bool property_get_revert(const StringName &p_name, Variant &r_ret) const override;