Open willnationsdev opened 3 years ago
Wouldn't it be simpler to add resource_saved
/resource_loaded
signals to ResourceSaver
/ResourceLoader
(and resource_reimported
signal probably to ResourceLoader
too, I'm not sure if it belongs in there)?
Ah, yeah, that would be another approach, and probably better overall too since it is more flexible and could accommodate both my own OOP approach or any other custom solution. I just initially thought of mimicking the way the ResourceFormatLoader/Saver stuff worked, but straight-up signals might be more efficient/simpler.
Describe the project you are working on
Plugins for RPG/simulation games/mod tools.
Describe the problem or limitation you are having in your project
Existing, ineffective solutions...
resources_reload
andresources_reimported
, but...changed
signal, but...changed
does not imply it is saved or loaded, so this can't detect when a file is saved or loaded anyway.ResourceSaver
andResourceLoader
singletons. No out-of-the-box integration.Describe the feature / enhancement and how it helps to overcome the problem or limitation
Now that Godot has first-class functions in the scripting API via Callable, we can add
filter
callbacks that can be registered to theResourceSaver
andResourceLoader
respectively. These would be callbacks that evaluate the currently saved/loaded resource, but do not impact the actual saver/loader logic.These callbacks can be implicitly auto-registered based on the existence of global script classes extending a
ResourceFilter
type.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Define a script-accessible type as below:
Have the ResourceLoader or ResourceSaver (one of them) create instances of all registered
ResourceFilter
types on startup and keep those cached for the duration of the app/editor. They can then sort them into pre-defined lists of filters based on whether they implement the corresponding above functions (so that they don't bother iterating over them if the method has no implementation).Whenever the corresponding operations occur in the respective singletons, iterate through the filters and call their methods. This may warrant a change to the default
ResourceSavedCallback
functionResourceSaver::save_callback
in both the app and editor contexts, but I'm not sure.If this enhancement will not be used often, can it be worked around with a few lines of script?
As mentioned, while there are alternative solutions that are powered by script code, they do not fully satisfy the needs of the feature.
Is there a reason why this should be core and not an add-on in the asset library?
See above.