Skip to content

Commit

Permalink
Optimize the custom doc for shaders.
Browse files Browse the repository at this point in the history


1. Remove `add_doc` for gdshader files without documentation.
2. Standardize the `class_doc.name` for custom documentation.
  • Loading branch information
magian1127 committed Oct 2, 2024
1 parent 76a1359 commit d5c37b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
5 changes: 1 addition & 4 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 17 additions & 10 deletions scene/resources/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()) {
Expand All @@ -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
Expand Down

0 comments on commit d5c37b4

Please sign in to comment.