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

Expose EditorFileSystemDirectory.get_file_resource_script_class() to scripting #11216

Open
Okxa opened this issue Nov 22, 2024 · 0 comments
Open

Comments

@Okxa
Copy link

Okxa commented Nov 22, 2024

Describe the project you are working on

Plugin which interacts with resource files in a project.

Describe the problem or limitation you are having in your project

There is no way to get class_name of a Resource with EditorFileSystemDirectory nor EditorFileSystem

(Sidenote; there is a way to get the type, but that is not the class_name:
https://docs.godotengine.org/en/stable/classes/class_editorfilesystem.html#class-editorfilesystem-method-get-file-type
https://docs.godotengine.org/en/latest/classes/class_editorfilesystemdirectory.html#class-editorfilesystemdirectory-method-get-file-type)

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

The FileInfo struct appears to have the desired information, according to the comment:

	struct FileInfo {
		String file;
		StringName type;
		StringName resource_script_class; // If any resource has script with a global class name, its found here.

https://github.com/godotengine/godot/blob/f952bfe9985ad8f507cc29b2c7601bbba18b8039/editor/editor_file_system.h#L59

However, there is no way to get this information in editor scripts.

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

Exposing the function get_file_resource_script_class() from EditorFileSystemDirectory to scripting would solve this:

StringName EditorFileSystemDirectory::get_file_resource_script_class(int p_idx) const {
	ERR_FAIL_INDEX_V(p_idx, files.size(), "");
	return files[p_idx]->resource_script_class;
}

https://github.com/godotengine/godot/blob/f952bfe9985ad8f507cc29b2c7601bbba18b8039/editor/editor_file_system.cpp#L189-L192

Also note that EditorFileSystem itself has a convience function to get the type of a file, (which internally uses EditorFileSystemDirectory):

String EditorFileSystem::get_file_type(const String &p_file) const {
	EditorFileSystemDirectory *fs = nullptr;
	int cpos = -1;

	if (!_find_file(p_file, &fs, cpos)) {
		return "";
	}

	return fs->files[cpos]->type;
}

https://github.com/godotengine/godot/blob/f952bfe9985ad8f507cc29b2c7601bbba18b8039/editor/editor_file_system.cpp#L1855-L1864

So it might be a good idea to also do that for this one, although that is left up to debate.

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

Only by loading the resource and checking for type, or reading the first line of a non-binary resource and manually checking for the script_class text.

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

Editor functionality.

@Okxa Okxa changed the title Expose get_file_resource_script_class() from EditorFileSystemDirectory to scripts. Expose EditorFileSystemDirectory.get_file_resource_script_class() to scripting. Nov 22, 2024
@Calinou Calinou changed the title Expose EditorFileSystemDirectory.get_file_resource_script_class() to scripting. Expose EditorFileSystemDirectory.get_file_resource_script_class() to scripting Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants