1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Name nodes added from drag & drop by name_casing

This commit is contained in:
foxydevloper
2021-07-29 00:26:34 -04:00
parent 48857194b3
commit 07a8f0fe38
2 changed files with 22 additions and 7 deletions

View File

@@ -5780,7 +5780,22 @@ bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_targe
}
void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) {
child->set_name(path.get_file().get_basename());
// Adjust casing according to project setting. The file name is expected to be in snake_case, but will work for others.
String name = path.get_file().get_basename();
switch (ProjectSettings::get_singleton()->get("editor/node_naming/name_casing").operator int()) {
case NAME_CASING_PASCAL_CASE:
name = name.capitalize().replace(" ", "");
break;
case NAME_CASING_CAMEL_CASE:
name = name.capitalize().replace(" ", "");
name[0] = name.to_lower()[0];
break;
case NAME_CASING_SNAKE_CASE:
name = name.capitalize().replace(" ", "_").to_lower();
break;
}
child->set_name(name);
Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(ResourceCache::get(path)));
Size2 texture_size = texture->get_size();