From f9d4f080901ffbe1b4cc92728c0bc41074068359 Mon Sep 17 00:00:00 2001 From: Pierre-Thomas Meisels Date: Thu, 10 Feb 2022 20:11:40 +0100 Subject: [PATCH] Fix ResourceSaver::save method exposition flag parameter enh: Add FLAG_NONE to SaverFlags in ResourceSaver to fix api inconsistency fix: flags parameter of ResourceSaver::save is now uint32_t to allow flag composition in scripts --- core/core_bind.cpp | 5 +++-- core/core_bind.h | 3 ++- core/io/resource_saver.h | 3 ++- doc/classes/ResourceSaver.xml | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 8d03f35617f..eae44a1bf3d 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -138,7 +138,7 @@ void ResourceLoader::_bind_methods() { ////// ResourceSaver ////// -Error ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFlags p_flags) { +Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + String(p_path) + "'."); return ::ResourceSaver::save(p_path, p_resource, p_flags); } @@ -157,9 +157,10 @@ Vector ResourceSaver::get_recognized_extensions(const RES &p_resource) { ResourceSaver *ResourceSaver::singleton = nullptr; void ResourceSaver::_bind_methods() { - ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &ResourceSaver::save, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &ResourceSaver::save, DEFVAL((uint32_t)FLAG_NONE)); ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions); + BIND_ENUM_CONSTANT(FLAG_NONE); BIND_ENUM_CONSTANT(FLAG_RELATIVE_PATHS); BIND_ENUM_CONSTANT(FLAG_BUNDLE_RESOURCES); BIND_ENUM_CONSTANT(FLAG_CHANGE_PATH); diff --git a/core/core_bind.h b/core/core_bind.h index ac0e92a87ab..974b913faab 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -93,6 +93,7 @@ protected: public: enum SaverFlags { + FLAG_NONE = 0, FLAG_RELATIVE_PATHS = 1, FLAG_BUNDLE_RESOURCES = 2, FLAG_CHANGE_PATH = 4, @@ -104,7 +105,7 @@ public: static ResourceSaver *get_singleton() { return singleton; } - Error save(const String &p_path, const RES &p_resource, SaverFlags p_flags); + Error save(const String &p_path, const RES &p_resource, uint32_t p_flags); Vector get_recognized_extensions(const RES &p_resource); ResourceSaver() { singleton = this; } diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 2919a4cec0a..ebc3be91a17 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -71,6 +71,7 @@ class ResourceSaver { public: enum SaverFlags { + FLAG_NONE = 0, FLAG_RELATIVE_PATHS = 1, FLAG_BUNDLE_RESOURCES = 2, FLAG_CHANGE_PATH = 4, @@ -80,7 +81,7 @@ public: FLAG_REPLACE_SUBRESOURCE_PATHS = 64, }; - static Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); + static Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = (uint32_t)FLAG_NONE); static void get_recognized_extensions(const RES &p_resource, List *p_extensions); static void add_resource_format_saver(Ref p_format_saver, bool p_at_front = false); static void remove_resource_format_saver(Ref p_format_saver); diff --git a/doc/classes/ResourceSaver.xml b/doc/classes/ResourceSaver.xml index 39f166db2e2..a7723c3f8d5 100644 --- a/doc/classes/ResourceSaver.xml +++ b/doc/classes/ResourceSaver.xml @@ -21,15 +21,18 @@ - + Saves a resource to disk to the given path, using a [ResourceFormatSaver] that recognizes the resource object. - The [code]flags[/code] bitmask can be specified to customize the save behavior. + The [code]flags[/code] bitmask can be specified to customize the save behavior using [enum SaverFlags] flags. Returns [constant OK] on success. + + No resource saving option. + Save the resource with a path relative to the scene which uses it.