Merge pull request #107770 from RandomShaper/fix_res_dupe_bindings
Enhance bindings of deep resource duplication
This commit is contained in:
@ -535,6 +535,10 @@ Ref<Resource> Resource::duplicate_deep(ResourceDeepDuplicateMode p_deep_subresou
|
||||
return dupe;
|
||||
}
|
||||
|
||||
Ref<Resource> Resource::_duplicate_deep_bind(DeepDuplicateMode p_deep_subresources_mode) const {
|
||||
return _duplicate_from_variant(true, (ResourceDeepDuplicateMode)p_deep_subresources_mode, 0);
|
||||
}
|
||||
|
||||
Ref<Resource> Resource::_duplicate_from_variant(bool p_deep, ResourceDeepDuplicateMode p_deep_subresources_mode, int p_recursion_count) const {
|
||||
// A call without deep duplication would have been early-rejected at Variant::duplicate() unless it's the root call.
|
||||
DEV_ASSERT(!(p_recursion_count > 0 && p_deep_subresources_mode == RESOURCE_DEEP_DUPLICATE_NONE));
|
||||
@ -724,12 +728,13 @@ void Resource::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("emit_changed"), &Resource::emit_changed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("duplicate", "deep"), &Resource::duplicate, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("duplicate_deep", "deep_subresources_mode"), &Resource::duplicate_deep, DEFVAL(RESOURCE_DEEP_DUPLICATE_INTERNAL));
|
||||
ClassDB::bind_method(D_METHOD("duplicate_deep", "deep_subresources_mode"), &Resource::_duplicate_deep_bind, DEFVAL(RESOURCE_DEEP_DUPLICATE_INTERNAL));
|
||||
|
||||
// For the bindings, it's much more natural to expose this enum from the Variant realm via Resource.
|
||||
ClassDB::bind_integer_constant(get_class_static(), StringName("ResourceDeepDuplicateMode"), "RESOURCE_DEEP_DUPLICATE_NONE", RESOURCE_DEEP_DUPLICATE_NONE);
|
||||
ClassDB::bind_integer_constant(get_class_static(), StringName("ResourceDeepDuplicateMode"), "RESOURCE_DEEP_DUPLICATE_INTERNAL", RESOURCE_DEEP_DUPLICATE_INTERNAL);
|
||||
ClassDB::bind_integer_constant(get_class_static(), StringName("ResourceDeepDuplicateMode"), "RESOURCE_DEEP_DUPLICATE_ALL", RESOURCE_DEEP_DUPLICATE_ALL);
|
||||
// Therefore, we can't use BIND_ENUM_CONSTANT here because we need some customization.
|
||||
ClassDB::bind_integer_constant(get_class_static(), StringName("DeepDuplicateMode"), "DEEP_DUPLICATE_NONE", RESOURCE_DEEP_DUPLICATE_NONE);
|
||||
ClassDB::bind_integer_constant(get_class_static(), StringName("DeepDuplicateMode"), "DEEP_DUPLICATE_INTERNAL", RESOURCE_DEEP_DUPLICATE_INTERNAL);
|
||||
ClassDB::bind_integer_constant(get_class_static(), StringName("DeepDuplicateMode"), "DEEP_DUPLICATE_ALL", RESOURCE_DEEP_DUPLICATE_ALL);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("changed"));
|
||||
ADD_SIGNAL(MethodInfo("setup_local_to_scene_requested"));
|
||||
|
||||
@ -96,6 +96,11 @@ private:
|
||||
Variant _duplicate_recursive(const Variant &p_variant, const DuplicateParams &p_params, uint32_t p_usage = 0) const;
|
||||
void _find_sub_resources(const Variant &p_variant, HashSet<Ref<Resource>> &p_resources_found);
|
||||
|
||||
// Only for binding the deep duplicate method, so it doesn't need actual members.
|
||||
enum DeepDuplicateMode : int;
|
||||
|
||||
_ALWAYS_INLINE_ Ref<Resource> _duplicate_deep_bind(DeepDuplicateMode p_deep_subresources_mode) const;
|
||||
|
||||
protected:
|
||||
virtual void _resource_path_changed();
|
||||
static void _bind_methods();
|
||||
@ -183,7 +188,7 @@ public:
|
||||
~Resource();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(ResourceDeepDuplicateMode);
|
||||
VARIANT_ENUM_CAST(Resource::DeepDuplicateMode);
|
||||
|
||||
class ResourceCache {
|
||||
friend class Resource;
|
||||
|
||||
@ -2262,6 +2262,8 @@ static void _register_variant_builtin_methods_math() {
|
||||
bind_static_method(Color, from_rgba8, sarray("r8", "g8", "b8", "a8"), varray(255));
|
||||
}
|
||||
|
||||
VARIANT_ENUM_CAST(ResourceDeepDuplicateMode);
|
||||
|
||||
static void _register_variant_builtin_methods_misc() {
|
||||
/* RID */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user