From 60eb59ab1934e331729e353690e2256dfe26d598 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 8 Mar 2024 21:16:16 +0100 Subject: [PATCH] Backpoered from Godot 4: Add is_built_in() method to Resource. - KoBeWi https://github.com/godotengine/godot/commit/e393c2a7348d96587e15af17c72ebeff719d4be3 --- core/io/resource_format_binary.cpp | 8 ++++---- core/object/object.cpp | 2 +- core/object/resource.h | 1 + editor/scene_tree_dock.cpp | 4 ++-- .../editor_script_editor.cpp | 20 +++++++------------ .../editor_script_text_editor.cpp | 2 +- .../script_editor_plugin.cpp | 8 +------- .../shader_editor/shader_editor_plugin.cpp | 4 ++-- scene/resources/packed_scene.cpp | 2 +- scene/resources/resource_format_text.cpp | 6 +++--- 10 files changed, 23 insertions(+), 34 deletions(-) diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index eebceccbd..7ff931819 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1598,7 +1598,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia return; // don't save it } - if (res->get_path().length() && res->get_path().find("::") == -1) { + if (!res->is_built_in()) { f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX); f->store_32(external_resources[res]); } else { @@ -1798,7 +1798,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant return; } - if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) { + if (!p_main && (!bundle_resources) && !res->is_built_in()) { if (res->get_path() == path) { ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded."); return; @@ -2029,7 +2029,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p for (List::Element *E = saved_resources.front(); E; E = E->next()) { RES r = E->get(); - if (r->get_path() == "" || r->get_path().find("::") != -1) { + if (!r->is_built_in()) { if (r->get_subindex() != 0) { if (used_indices.has(r->get_subindex())) { r->set_subindex(0); //repeated @@ -2042,7 +2042,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p for (List::Element *E = saved_resources.front(); E; E = E->next()) { RES r = E->get(); - if (r->get_path() == "" || r->get_path().find("::") != -1) { + if (!r->is_built_in()) { if (r->get_subindex() == 0) { int new_subindex = 1; if (used_indices.size()) { diff --git a/core/object/object.cpp b/core/object/object.cpp index f6ec15e71..94c38bb59 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1612,7 +1612,7 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) { return; } - if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1) { + if (!r->is_built_in()) { return; //not an internal resource } diff --git a/core/object/resource.h b/core/object/resource.h index 0f4b1e930..17b6afe53 100644 --- a/core/object/resource.h +++ b/core/object/resource.h @@ -101,6 +101,7 @@ public: virtual void set_path(const String &p_path, bool p_take_over = false); String get_path() const; + _FORCE_INLINE_ bool is_built_in() const { return path_cache.empty() || path_cache.find("::") != -1 || path_cache.begins_with("local://"); } void set_subindex(int p_sub_index); int get_subindex() const; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 123cd9a21..909568af0 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -3377,7 +3377,7 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, RBMap &r_rema continue; } - if ((res->get_path() == "" || res->get_path().find("::") > -1) && !r_remap.has(res)) { + if (res->is_built_in() && !r_remap.has(res)) { _create_remap_for_resource(res, r_remap); } } @@ -3404,7 +3404,7 @@ void SceneTreeDock::_create_remap_for_resource(RES p_resource, RBMap & if (v.is_ref()) { RES res = v; if (res.is_valid()) { - if ((res->get_path() == "" || res->get_path().find("::") > -1) && !r_remap.has(res)) { + if (res->is_built_in() && !r_remap.has(res)) { _create_remap_for_resource(res, r_remap); } } diff --git a/editor_modules/editor_code_editor/editor_script_editor.cpp b/editor_modules/editor_code_editor/editor_script_editor.cpp index 3d0c5b760..5708e545c 100644 --- a/editor_modules/editor_code_editor/editor_script_editor.cpp +++ b/editor_modules/editor_code_editor/editor_script_editor.cpp @@ -101,12 +101,6 @@ #include "shader_editor/shader_editor_plugin.h" #endif -static bool _is_built_in_script(Script *p_script) { - String path = p_script->get_path(); - - return path.find("::") != -1; -} - class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { struct Cache { uint64_t time_loaded; @@ -496,7 +490,7 @@ void EditorScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) Ref