From d4d6a20deb2a1a42b635cd012718355b3dd66a69 Mon Sep 17 00:00:00 2001 From: Magian Date: Sun, 29 Sep 2024 20:37:44 +0800 Subject: [PATCH] =?UTF-8?q?Optimize=20the=20custom=20doc=20for=20shaders.?= =?UTF-8?q?=20=EF=BB=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Remove `add_doc` for gdshader files without documentation. 2. Standardize the `class_doc.name` for custom documentation. --- editor/editor_inspector.cpp | 5 +---- scene/resources/shader.cpp | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index a215662f167..dde3a30c9de 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3474,10 +3474,7 @@ void EditorInspector::update_tree() { // `|` separators used in `EditorHelpBit`. if (theme_item_name.is_empty()) { if (p.name.contains("shader_parameter/")) { - ShaderMaterial *shader_material = Object::cast_to(object); - if (shader_material) { - ep->set_tooltip_text("property|" + shader_material->get_shader()->get_path() + "|" + property_prefix + p.name); - } + ep->set_tooltip_text("property|" + p.class_name + "|" + property_prefix + p.name); } else if (p.usage & PROPERTY_USAGE_INTERNAL) { ep->set_tooltip_text("internal_property|" + classname + "|" + property_prefix + p.name); } else { diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 46d38146a67..c13300e6cfe 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -130,10 +130,16 @@ void Shader::get_shader_uniform_list(List *p_params, bool p_get_gr List local; RenderingServer::get_singleton()->get_shader_parameter_list(shader, &local); -#ifdef TOOLS_ENABLED +#if defined(TOOLS_ENABLED) && defined(MODULE_REGEX_ENABLED) DocData::ClassDoc class_doc; - class_doc.name = get_path(); - class_doc.is_script_doc = true; + bool generate_doc = EditorHelp::get_doc_data() != nullptr && Engine::get_singleton()->is_editor_hint() && !get_path().is_empty(); + if (generate_doc) { + class_doc.name = get_path().trim_prefix("res://").quote(); + class_doc.is_script_doc = true; + if (EditorHelp::get_doc_data()->has_doc(class_doc.name)) { + EditorHelp::get_doc_data()->remove_doc(class_doc.name); + } + } #endif for (PropertyInfo &pi : local) { @@ -151,11 +157,10 @@ void Shader::get_shader_uniform_list(List *p_params, bool p_get_gr if (pi.type == Variant::RID) { pi.type = Variant::OBJECT; } -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { +#if defined(TOOLS_ENABLED) && defined(MODULE_REGEX_ENABLED) + if (generate_doc) { DocData::PropertyDoc prop_doc; prop_doc.name = "shader_parameter/" + pi.name; -#ifdef MODULE_REGEX_ENABLED const RegEx pattern("/\\*\\*\\s([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/\\s*uniform\\s+\\w+\\s+" + pi.name + "(?=[\\s:;=])"); Ref pattern_ref = pattern.search(code); if (pattern_ref.is_valid()) { @@ -165,16 +170,17 @@ void Shader::get_shader_uniform_list(List *p_params, bool p_get_gr RegExMatch *match_tip = pattern_tip_ref.ptr(); const RegEx pattern_stripped("\\n\\s*\\*\\s*"); prop_doc.description = pattern_stripped.sub(match_tip->get_string(1), "\n", true); + + pi.class_name = class_doc.name; + class_doc.properties.push_back(prop_doc); } -#endif - class_doc.properties.push_back(prop_doc); } #endif p_params->push_back(pi); } } -#ifdef TOOLS_ENABLED - if (EditorHelp::get_doc_data() != nullptr && Engine::get_singleton()->is_editor_hint() && !class_doc.name.is_empty() && p_params) { +#if defined(TOOLS_ENABLED) && defined(MODULE_REGEX_ENABLED) + if (generate_doc && class_doc.properties.size() > 0) { EditorHelp::get_doc_data()->add_doc(class_doc); } #endif