diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/visual_shader.cpp | 10 | ||||
-rw-r--r-- | scene/resources/visual_shader.h | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index a3813f8fc6..7265c9b457 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -257,7 +257,7 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port); VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port); - if (MAX(0, from_port_type - 2) != (MAX(0, to_port_type - 2))) { + if (!is_port_types_compatible(from_port_type, to_port_type)) { return false; } @@ -271,6 +271,10 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po return true; } +bool VisualShader::is_port_types_compatible(int p_a, int p_b) const { + return MAX(0, p_a - 2) == (MAX(0, p_b - 2)); +} + void VisualShader::connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { ERR_FAIL_INDEX(p_type, TYPE_MAX); Graph *g = &graph[p_type]; @@ -295,8 +299,8 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port, VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port); VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port); - if (MAX(0, from_port_type - 2) != (MAX(0, to_port_type - 2))) { - ERR_EXPLAIN("Incompatible port types (scalar/vec/bool with transform"); + if (!is_port_types_compatible(from_port_type, to_port_type)) { + ERR_EXPLAIN("Incompatible port types (scalar/vec/bool) with transform"); ERR_FAIL_V(ERR_INVALID_PARAMETER); return ERR_INVALID_PARAMETER; } diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index a36776e701..83db51b1b0 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -138,6 +138,7 @@ public: Error connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); void disconnect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); void connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); + bool is_port_types_compatible(int p_a, int p_b) const; void rebuild(); void get_node_connections(Type p_type, List<Connection> *r_connections) const; |