From 84c525ba1bec018e75679334238fec5af942dabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 10 Oct 2016 13:06:13 +0200 Subject: [PATCH] Revise serial naming behavior --- scene/main/node.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0c1b8e52e97..6e33dcb4c9e 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1310,6 +1310,7 @@ String Node::_generate_serial_child_name(Node *p_child) { name = p_child->get_type(); } + // Extract trailing number String nums; for(int i=name.length()-1;i>=0;i--) { CharType n=name[i]; @@ -1320,18 +1321,20 @@ String Node::_generate_serial_child_name(Node *p_child) { } } - int num=nums.to_int(); - if (num<1) - num=1; - String nnsep=_get_name_num_separator(); - name = name.substr(0,name.length()-nums.length()).strip_edges(); - if ( name.substr(name.length()-nnsep.length(),nnsep.length()) == nnsep) { - name = name.substr(0,name.length()-nnsep.length()); + int num=0; + bool explicit_zero=false; + if (nums.length()>0 && name.substr(name.length()-nnsep.length()-nums.length(),nnsep.length()) == nnsep) { + // Base name + Separator + Number + num=nums.to_int(); + name=name.substr(0,name.length()-nnsep.length()-nums.length()); // Keep base name + if (num==0) { + explicit_zero=true; + } } for(;;) { - String attempt = (name + (num > 1 ? nnsep + itos(num) : "")).strip_edges(); + String attempt = (name + (num > 0 || explicit_zero ? nnsep + itos(num) : "")).strip_edges(); bool found=false; for(int i=0;i