diff options
author | kobewi <kobewi4e@gmail.com> | 2022-08-18 13:47:05 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-08-18 14:08:40 +0200 |
commit | fdab23163fcebda3b6e795a74528100414a389ba (patch) | |
tree | 28d4ce173435e26dcebe2ad1b09e6aa25f034ef3 /scene | |
parent | 03dc8c5d6fc4a1cc8c0b8b329ae53a3d0d8b3074 (diff) |
Unify node casing adjustment
Diffstat (limited to 'scene')
-rw-r--r-- | scene/main/node.cpp | 30 | ||||
-rw-r--r-- | scene/main/node.h | 1 |
2 files changed, 18 insertions, 13 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index ea9788de27..9fe3e9a87a 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -948,6 +948,21 @@ String Node::validate_child_name(Node *p_child) { } #endif +String Node::adjust_name_casing(const String &p_name) { + switch (GLOBAL_GET("editor/node_naming/name_casing").operator int()) { + case NAME_CASING_PASCAL_CASE: + return p_name.capitalize().replace(" ", ""); + case NAME_CASING_CAMEL_CASE: { + String name = p_name.capitalize().replace(" ", ""); + name[0] = name.to_lower()[0]; + return name; + } + case NAME_CASING_SNAKE_CASE: + return p_name.capitalize().replace(" ", "_").to_lower(); + } + return p_name; +} + void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { /* Make sure the name is unique */ @@ -1021,19 +1036,8 @@ void Node::_generate_serial_child_name(const Node *p_child, StringName &name) co //no name and a new name is needed, create one. name = p_child->get_class(); - // Adjust casing according to project setting. The current type name is expected to be in PascalCase. - switch (ProjectSettings::get_singleton()->get("editor/node_naming/name_casing").operator int()) { - case NAME_CASING_PASCAL_CASE: - break; - case NAME_CASING_CAMEL_CASE: { - String n = name; - n[0] = n.to_lower()[0]; - name = n; - } break; - case NAME_CASING_SNAKE_CASE: - name = String(name).camelcase_to_underscore(true); - break; - } + // Adjust casing according to project setting. + name = adjust_name_casing(name); } //quickly test if proposed name exists diff --git a/scene/main/node.h b/scene/main/node.h index ccd1d561d2..99a98c961e 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -459,6 +459,7 @@ public: #ifdef TOOLS_ENABLED String validate_child_name(Node *p_child); #endif + static String adjust_name_casing(const String &p_name); void queue_delete(); |