Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-11-12 21:22:43 +0300
committerHans Goudey <h.goudey@me.com>2021-11-12 21:22:43 +0300
commitd845ba481c6d2ef50bf87bec834555d5e1faf64c (patch)
tree37470427a60e483c6fae7e1563263d2fd6f504e7 /source/blender/blenloader/intern/versioning_common.cc
parentcbca71a7cff394b0c5d670f87f2b480f526ba6dd (diff)
Fix T91826: Inconsistent node socket name identifier separator
Previously both `.` and `_` were used as separators when finding a unique name for a socket. This removes the use of `.`, since `_` was more common. It also does versioning for all of a file's node trees to make sure that they all use the `_` convention. Differential Revision: https://developer.blender.org/D13181
Diffstat (limited to 'source/blender/blenloader/intern/versioning_common.cc')
-rw-r--r--source/blender/blenloader/intern/versioning_common.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc
index 61119b80fdd..af765be619f 100644
--- a/source/blender/blenloader/intern/versioning_common.cc
+++ b/source/blender/blenloader/intern/versioning_common.cc
@@ -27,6 +27,7 @@
#include "BLI_listbase.h"
#include "BLI_string.h"
+#include "BLI_string_ref.hh"
#include "BKE_animsys.h"
#include "BKE_lib_id.h"
@@ -37,6 +38,8 @@
#include "versioning_common.h"
+using blender::StringRef;
+
ARegion *do_versions_add_region_if_not_found(ListBase *regionbase,
int region_type,
const char *name,
@@ -101,6 +104,30 @@ static void change_node_socket_name(ListBase *sockets, const char *old_name, con
}
}
+/**
+ * Convert `SocketName.001` unique name format to `SocketName_001`. Previously both were used.
+ */
+void version_node_socket_id_delim(bNodeSocket *socket)
+{
+ StringRef name = socket->name;
+ StringRef id = socket->identifier;
+
+ if (!id.startswith(name)) {
+ /* We only need to affect the case where the identifier starts with the name. */
+ return;
+ }
+
+ StringRef id_number = id.drop_known_prefix(name);
+ if (id_number.is_empty()) {
+ /* The name was already unique, and didn't need numbers at the end for the id. */
+ return;
+ }
+
+ if (id_number.startswith(".")) {
+ socket->identifier[name.size()] = '_';
+ }
+}
+
void version_node_socket_name(bNodeTree *ntree,
const int node_type,
const char *old_name,