summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorSilc Renew <tokage.it.lab@gmail.com>2023-01-30 05:13:43 +0900
committerSilc Renew <tokage.it.lab@gmail.com>2023-01-30 07:53:42 +0900
commitdf5092904380c10715068a9d1e25e5c2bbb75b9d (patch)
tree462a36432c5a2765d26125ef831cdc8f5cfca674 /editor/plugins
parenta3dae9e548e5fbab7b7be070cf71f972656f759b (diff)
Tweak the name for duplicated animations in the editor
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 30e06bfcf4..b33ad67f23 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -1105,9 +1105,24 @@ void AnimationPlayerEditor::_animation_duplicate() {
return;
}
+ int count = 2;
String new_name = current;
- while (player->has_animation(new_name)) {
- new_name = new_name + " (copy)";
+ PackedStringArray split = new_name.split("_");
+ int last_index = split.size() - 1;
+ if (last_index > 0 && split[last_index].is_valid_int() && split[last_index].to_int() >= 0) {
+ count = split[last_index].to_int();
+ split.remove_at(last_index);
+ new_name = String("_").join(split);
+ }
+ while (true) {
+ String attempt = new_name;
+ attempt += vformat("_%d", count);
+ if (player->has_animation(attempt)) {
+ count++;
+ continue;
+ }
+ new_name = attempt;
+ break;
}
if (new_name.contains("/")) {