-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Add metadata to resource previews #64628
Conversation
if (p_str.begins_with("ID:")) { | ||
hash = uint32_t(p_str.get_slicec(':', 2).to_int()); | ||
path = "ID:" + p_str.get_slicec(':', 1); | ||
} else { | ||
modified_time = FileAccess::get_modified_time(path); | ||
if (!p_path.begins_with("ID:")) { | ||
modified_time = FileAccess::get_modified_time(p_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a bonus refactoring.
Ok this is probably ready to review. The metadata is correctly saved and loaded. Not sure how to force cache invalidation though; old previews don't have metadata stored. |
356e480
to
bcf9851
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me. Lacking @reduz's explicit go but it doesn't seem too critical, he can validate later if needed.
Edit: Discussed it with reduz:
I am just not happy with the approach in general, but thinking how to do this properly is a good amount of work
we can probably still merge it anyway
If its important, it can be merged as-is, its fine
Needs a rebase. Might also be good to clarify what [param metadata]
is used for in the docs.
Rebased. I clarified the |
Needs another rebase to fix CI. |
I promise the CI failure isn't my fault this time :P |
Thanks! |
@@ -35,6 +35,7 @@ | |||
#include "core/io/resource_loader.h" | |||
#include "core/io/resource_saver.h" | |||
#include "core/object/message_queue.h" | |||
#include "core/variant/variant_utility.cpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new required argument breaks compatibility, my plugin that was working from Godot 4.0 is no longer working in 4.1:
And if I fix this, it won't work in 4.0 anymore. |
Prerequisite for #63263
This PR adds preview metadata to EditorResourcePreview. A metadata can be image dimensions, audio stream length, model triangle count etc. In #63263 I want to display this information in a tooltip, but the problem is that fetching this information requires loading the resource, which can be costly sometimes. This PR allows to easily retrieve and cache the metadata, because generators already load the resource to make the preview.
What I do is pass a HashMap to the
generate()
method of EditorResourcePreviewGenerator and the generator can add any metadata to that hashmap. It can be later retrieved by using resource path + metadata name. For now I only added "dimensions" metadata for textures.Marking as draft because:
Any advice on these welcome, but I'll try to figure it out myself.