Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the file path with the UID when using Ctrl + drag and drop #11694

Open
nubels opened this issue Feb 3, 2025 · 3 comments · May be fixed by godotengine/godot#99094
Open

Replace the file path with the UID when using Ctrl + drag and drop #11694

nubels opened this issue Feb 3, 2025 · 3 comments · May be fixed by godotengine/godot#99094

Comments

@nubels
Copy link

nubels commented Feb 3, 2025

Describe the project you are working on

A Point & Click Adventure

Describe the problem or limitation you are having in your project

When you drag and drop a file from the FileSystem dock while holding ctrl it creates a const using the preload method. Currently, it uses the path of the file. This path no longer works when you move the file to another location. With the push for UIDs, I think it makes sense to change this behaviour.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Replace the path with the UID of the file.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This would be my first pull request and I'm not sure about the codestyle and various details so I wanted to talk to other developers before creating the pull request. This is how I'd change the _get_dropped_resource_line in script_text_editor.cpp to implement this proposal. I've tested the behaviour and it works fine.

static String _get_dropped_resource_line(const Ref<Resource> &p_resource, bool p_create_field) {
	const String &path = p_resource->get_path();
	const bool is_script = ClassDB::is_parent_class(p_resource->get_class(), "Script");
	const String id = ResourceUID::get_singleton()->path_to_uid(path);
	const bool has_id = ResourceUID::get_singleton()->has_id(ResourceUID::get_singleton()->text_to_id(id));

	String drop_data = "";

	if (has_id) {
		drop_data = _quote_drop_data(id);
	} else {
		drop_data = _quote_drop_data(path);
	}

	if (!p_create_field) {
		return vformat("preload(%s)", drop_data);
	}

	String variable_name = p_resource->get_name();
	if (variable_name.is_empty()) {
		variable_name = path.get_file().get_basename();
	}

	if (is_script) {
		variable_name = variable_name.to_pascal_case().validate_unicode_identifier();
	} else {
		variable_name = variable_name.to_snake_case().to_upper().validate_unicode_identifier();
	}
	return vformat("const %s = preload(%s)", variable_name, drop_data);
}
Screencast_20250203_131402.webm

If this enhancement will not be used often, can it be worked around with a few lines of script?

I think it will be used often and a workaround seems inconvenient to me.

Is there a reason why this should be core and not an add-on in the asset library?

This is about making preload constants more resilient to changes in the filesystem.

@Calinou Calinou changed the title Replace the path with the uid when using ctrl + drag and drop Replace the file path with the UID when using Ctrl + drag and drop Feb 3, 2025
@Calinou
Copy link
Member

Calinou commented Feb 3, 2025

I thought this already existed by holding Shift or Alt while also holding Ctrl, but I may be mistaken.

cc @KoBeWi

@nubels
Copy link
Author

nubels commented Feb 3, 2025

I thought this already existed by holding Shift or Alt while also holding Ctrl, but I may be mistaken.

cc @KoBeWi

I've tested these shortcuts in Godot 4.4 beta 2 and the current version of main, it doesn't seem to be implemented yet.

@KoBeWi
Copy link
Member

KoBeWi commented Feb 3, 2025

There is only godotengine/godot#99094
I forgot to mark it as ready .-.

@KoBeWi KoBeWi linked a pull request Feb 13, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants