Optimize the custom doc for shaders.



1. Remove `add_doc` for gdshader files without documentation.
2. Standardize the `class_doc.name` for custom documentation.
This commit is contained in:
Magian 2024-10-02 13:33:15 +08:00
parent 76a135926a
commit d5c37b4a0e
2 changed files with 18 additions and 14 deletions

View file

@ -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<ShaderMaterial>(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 {

View file

@ -130,10 +130,17 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_gr
List<PropertyInfo> 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;
class_doc.inherits = "Shader";
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 +158,10 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *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<RegExMatch> pattern_ref = pattern.search(code);
if (pattern_ref.is_valid()) {
@ -165,16 +171,17 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *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