diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-12-02 13:23:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-02 13:23:54 +0100 |
commit | f34f1c1bb33f2841dd10c6ebdde0447dd36aebc6 (patch) | |
tree | 3bc5fba048f3bf9176d97b3a14cd8232044d1871 /scene/resources | |
parent | de5a956ea1e17b1f02e1d7363d44dd0a350fc29f (diff) | |
parent | dd32d7b7eed45dc18434995592df163d4f9d6760 (diff) |
Merge pull request #44036 from Chaosus/vs_fix_expression
Fixed some errors when changing port name in visual shader expressions
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/visual_shader.cpp | 41 | ||||
-rw-r--r-- | scene/resources/visual_shader.h | 2 |
2 files changed, 23 insertions, 20 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index dd9f64693e..34129e35da 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -811,8 +811,12 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port #define IS_SYMBOL_CHAR(m_d) (((m_d) >= 'a' && (m_d) <= 'z') || ((m_d) >= 'A' && (m_d) <= 'Z') || ((m_d) >= '0' && (m_d) <= '9') || (m_d) == '_') -String VisualShader::validate_port_name(const String &p_name, const List<String> &p_input_ports, const List<String> &p_output_ports) const { - String name = p_name; +String VisualShader::validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const { + String name = p_port_name; + + if (name == String()) { + return String(); + } while (name.length() && !IS_INITIAL_CHAR(name[0])) { name = name.substr(1, name.length() - 1); @@ -830,29 +834,28 @@ String VisualShader::validate_port_name(const String &p_name, const List<String> } name = valid_name; + } else { + return String(); } - String valid_name = name; - bool is_equal = false; + List<String> input_names; + List<String> output_names; - for (int i = 0; i < p_input_ports.size(); i++) { - if (name == p_input_ports[i]) { - is_equal = true; - break; + for (int i = 0; i < p_node->get_input_port_count(); i++) { + if (!p_output && i == p_port_id) { + continue; } - } - - if (!is_equal) { - for (int i = 0; i < p_output_ports.size(); i++) { - if (name == p_output_ports[i]) { - is_equal = true; - break; - } + if (name == p_node->get_input_port_name(i)) { + return String(); } } - - if (is_equal) { - name = ""; + for (int i = 0; i < p_node->get_output_port_count(); i++) { + if (p_output && i == p_port_id) { + continue; + } + if (name == p_node->get_output_port_name(i)) { + return String(); + } } return name; diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 41c4642ee3..a38c2886e2 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -175,7 +175,7 @@ public: String generate_preview_shader(Type p_type, int p_node, int p_port, Vector<DefaultTextureParam> &r_default_tex_params) const; - String validate_port_name(const String &p_name, const List<String> &p_input_ports, const List<String> &p_output_ports) const; + String validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const; String validate_uniform_name(const String &p_name, const Ref<VisualShaderNodeUniform> &p_uniform) const; VisualShader(); |