Fix AnimationNodeStateMachine::rename_node

This commit is contained in:
Guilherme Felipe de C. G. da Silva 2022-07-31 18:47:19 -03:00
parent 214d0b20b0
commit 0ad580a740
2 changed files with 15 additions and 15 deletions

View file

@ -830,20 +830,12 @@ void AnimationNodeStateMachine::rename_node(const StringName &p_name, const Stri
anodesm->state_machine_name = p_new_name; anodesm->state_machine_name = p_new_name;
} }
for (int i = 0; i < transitions.size(); i++) { _rename_transitions(p_name, p_new_name);
if (transitions[i].local_from == p_name) {
_rename_transition(transitions[i].from, String(transitions[i].from).replace_first(p_name, p_new_name));
}
if (transitions[i].local_to == p_name) {
_rename_transition(transitions[i].to, String(transitions[i].to).replace_first(p_name, p_new_name));
}
}
emit_signal("tree_changed"); emit_signal("tree_changed");
} }
void AnimationNodeStateMachine::_rename_transition(const StringName &p_name, const StringName &p_new_name) { void AnimationNodeStateMachine::_rename_transitions(const StringName &p_name, const StringName &p_new_name) {
if (updating_transitions) { if (updating_transitions) {
return; return;
} }
@ -854,12 +846,16 @@ void AnimationNodeStateMachine::_rename_transition(const StringName &p_name, con
Vector<String> path = String(transitions[i].to).split("/"); Vector<String> path = String(transitions[i].to).split("/");
if (path.size() > 1) { if (path.size() > 1) {
if (path[0] == "..") { if (path[0] == "..") {
prev_state_machine->_rename_transition(String(state_machine_name) + "/" + p_name, String(state_machine_name) + "/" + p_new_name); prev_state_machine->_rename_transitions(String(state_machine_name) + "/" + p_name, String(state_machine_name) + "/" + p_new_name);
} else { } else {
((Ref<AnimationNodeStateMachine>)states[transitions[i].local_to].node)->_rename_transition("../" + p_name, "../" + p_new_name); ((Ref<AnimationNodeStateMachine>)states[transitions[i].local_to].node)->_rename_transitions("../" + p_name, "../" + p_new_name);
} }
} }
if (transitions[i].local_from == p_name) {
transitions.write[i].local_from = p_new_name;
}
transitions.write[i].from = p_new_name; transitions.write[i].from = p_new_name;
} }
@ -867,12 +863,16 @@ void AnimationNodeStateMachine::_rename_transition(const StringName &p_name, con
Vector<String> path = String(transitions[i].from).split("/"); Vector<String> path = String(transitions[i].from).split("/");
if (path.size() > 1) { if (path.size() > 1) {
if (path[0] == "..") { if (path[0] == "..") {
prev_state_machine->_rename_transition(String(state_machine_name) + "/" + p_name, String(state_machine_name) + "/" + p_new_name); prev_state_machine->_rename_transitions(String(state_machine_name) + "/" + p_name, String(state_machine_name) + "/" + p_new_name);
} else { } else {
((Ref<AnimationNodeStateMachine>)states[transitions[i].local_from].node)->_rename_transition("../" + p_name, "../" + p_new_name); ((Ref<AnimationNodeStateMachine>)states[transitions[i].local_from].node)->_rename_transitions("../" + p_name, "../" + p_new_name);
} }
} }
if (transitions[i].local_to == p_name) {
transitions.write[i].local_to = p_new_name;
}
transitions.write[i].to = p_new_name; transitions.write[i].to = p_new_name;
} }

View file

@ -185,7 +185,7 @@ private:
void _tree_changed(); void _tree_changed();
void _remove_transition(const Ref<AnimationNodeStateMachineTransition> p_transition); void _remove_transition(const Ref<AnimationNodeStateMachineTransition> p_transition);
void _rename_transition(const StringName &p_name, const StringName &p_new_name); void _rename_transitions(const StringName &p_name, const StringName &p_new_name);
bool _can_connect(const StringName &p_name, Vector<AnimationNodeStateMachine *> p_parents = Vector<AnimationNodeStateMachine *>()); bool _can_connect(const StringName &p_name, Vector<AnimationNodeStateMachine *> p_parents = Vector<AnimationNodeStateMachine *>());
StringName _get_shortest_path(const StringName &p_path) const; StringName _get_shortest_path(const StringName &p_path) const;