Skip to content

Commit

Permalink
Fix few bugs in visual shader expressions
Browse files Browse the repository at this point in the history
Fixed few bugs in visual shader expressions
  • Loading branch information
Chaosus committed Dec 1, 2020
1 parent 339b646 commit b74f1ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,17 @@ void VisualShaderEditor::_remove_output_port(int p_node, int p_port) {
}
}

int preview_port = node->get_output_port_for_preview();
if (preview_port != -1) {
if (preview_port == p_port) {
undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", -1);
undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
} else if (preview_port > p_port) {
undo_redo->add_do_method(node.ptr(), "set_output_port_for_preview", preview_port - 1);
undo_redo->add_undo_method(node.ptr(), "set_output_port_for_preview", preview_port);
}
}

undo_redo->add_do_method(node.ptr(), "remove_output_port", p_port);
undo_redo->add_undo_method(node.ptr(), "add_output_port", p_port, (int)node->get_output_port_type(p_port), node->get_output_port_name(p_port));

Expand Down
8 changes: 6 additions & 2 deletions scene/resources/visual_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2767,8 +2767,10 @@ void VisualShaderNodeGroupBase::remove_input_port(int p_id) {
inputs.erase(index, count);

inputs_strings = inputs.split(";", false);
inputs = inputs.substr(0, index);

for (int i = p_id; i < inputs_strings.size(); i++) {
inputs = inputs.replace_first(inputs_strings[i].split(",")[0], itos(i));
inputs += inputs_strings[i].replace_first(inputs_strings[i].split(",")[0], itos(i)) + ";";
}

_apply_port_changes();
Expand Down Expand Up @@ -2837,8 +2839,10 @@ void VisualShaderNodeGroupBase::remove_output_port(int p_id) {
outputs.erase(index, count);

outputs_strings = outputs.split(";", false);
outputs = outputs.substr(0, index);

for (int i = p_id; i < outputs_strings.size(); i++) {
outputs = outputs.replace_first(outputs_strings[i].split(",")[0], itos(i));
outputs += outputs_strings[i].replace_first(outputs_strings[i].split(",")[0], itos(i)) + ";";
}

_apply_port_changes();
Expand Down

0 comments on commit b74f1ab

Please sign in to comment.