tools: Add script to check for orphan assets - #2787
Conversation
I've been using this in StoryQuests submissions.
|
Play this branch at https://play.threadbare.game/branches/endlessm/orphans-tool/. (This launches the game from the start, not directly at the change(s) in this pull request.) |
Using the output of tools/check_orphan_assets.gd and confirming that they are also not referenced from scripts by filename or UID.
|
If we merge this, we should update https://github.com/endlessm/threadbare/wiki/Reviewing-a-StoryQuest-submission#checking-for-unneeded-files |
wjt
left a comment
There was a problem hiding this comment.
If this is useful, let's ship it!
I can think of some changes I might make - noted below - but this is the kind of script that we can incrementally improve as we use it.
| ## Extensions considered assets, lowercase and without the dot. | ||
| const ASSET_EXTENSIONS: PackedStringArray = [ | ||
| "png", "jpg", "jpeg", "webp", "svg", "ogg", "wav", "mp3", "ttf", "otf", "ogv" | ||
| ] |
There was a problem hiding this comment.
I was trying to see whether this hardcoded list could be avoided. For example, .dialogue files are potentially-orphaned "assets" of a sort...
I tried using ResourceLoader.list_directory() rather than the DirAccess methods. By definition this only includes files that Godot recognises as resources (which includes .gd files but not, for example, Markdown files). It also includes files where you have an .import file but the corresponding file has been deleted (!!) but only because the imported texture (for example) is in the .godot cache.
Not sure it's an improvement.
There was a problem hiding this comment.
Yes this list is actually the file extensions in .gitattributes, excluding files not recognized by Godot (currently just .aseprite). Let me check with ResourceLoader.list_directory()!.
| for directory: String in DirAccess.get_directories_at(current): | ||
| # Godot's own cache holds copies of everything and would count as | ||
| # references to assets that are otherwise unused. | ||
| if directory != ".godot": |
There was a problem hiding this comment.
I think if you use the non-static methods of DirAccess - i.e. open the dir with DirAccess.open() then iterate d.get_directories() - then you could use the include_hidden property (i.e. set it to false) to avoid having to filter this by hand.
There was a problem hiding this comment.
Thanks for the hints! I will try them.
I've been using this in StoryQuests submissions.
StoryQuests: Remove unused assets
Using the output of tools/check_orphan_assets.gd and confirming that they are
also not referenced from scripts by filename or UID.
Except for Champ, because these assets could be actual placeholders.