Add the ability for PackedScenes and GDScripts to have import files #98029
+362
−27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I added the ability for PackedScenes and GDScripts to have import files. To accomplish that I had to make two fundamental changes to Godot:
Add the concept of "read only or not" to "resource assets" (resource assets = assets with import files). Previously Godot assumed any resource asset was read only. PackedScenes and GDScripts are not read only and can be edited/saved directly. In addition on export we want to use those assets directly not their corresponding files in the .godot folder (e.g. for a texture on export Godot wouldn't use the reference resource asset "someTexture.png" file but the corresponding encoded etc2/dxt/etc texture in the .godot folder. For packedscenes/gdscripts though we want to use the reference resource asset).
When loading assets, use the "import order" on asset loaders to pick the right one instead of picking the first one Godot finds (see ResourceLoader::_load in resource_loader.cpp). We do this because by creating importers for PackedScenes and GDScripts, we are also creating loaders for those asset types. But PackedScenes and GDScripts already have native loaders, so we need to make sure those "native loaders" get picked over our "importing loaders". We do this by setting our importing loaders with a lower import order and changing ResourceLoader to use those orders when finding the right loader to choose.
This is "step one" in my effort to add "pack file tags" to facilitate exporting many pack files (godotengine/godot-proposals#10580). I tested this change with various godot projects and exporting to Windows/Android platforms.