derkork / godot-resource-groups

An add-on for the Godot engine that simplifies handling of resources
MIT License
183 stars 6 forks source link

Option for manual-only saving/updating #7

Closed skison closed 2 months ago

skison commented 2 months ago

Hey there, would it be possible to add an option somewhere to only save/update resource groups manually? I have a habit of ctrl+s saving my project all the time, but every time I save (even with no resource changes) there is a noticeable time delay & cluttering of the console output when the plugin is enabled. I imagine this could be fixed by changing when the saving occurs, however I know not everyone would want this enabled, so I think this would make sense as an opt-in feature!

Ideally, the best option would be to keep the auto-save enabled and only run the more expensive logic right when it is needed, like when the directory structure changes, but that sounds like it could be a pain to implement! So maybe a simpler option like this would be a good enough compromise.

If this is added, it would be great to see an option to update individual groups (e.g. with a button in the Inspector of a selected group), and an option to update all groups, possibly using a button within a custom Resource Groups editor tab/window.

Thanks for the great work on this plugin!

derkork commented 2 months ago

I really would like to keep the automatic update in so people don't forget to do it and open a ton of tickets about how the plugin isn't working. Also just out of curiosity how many files are you working with so you are seeing delays? The example has 1000 images which pretty much runs instantly on my machine, so I wonder what would cause delays in your project?

Regarding the other issue - as you mentioned, ideally the plugin would only rebuild the resource groups when something has changed in the project and I already tried implementing this. But there does not seem to be any callback in the Godot Editor API that would inform me of changes to the project. There is a resource_saved which is only triggered when you save resources. It's not triggered on any other file change (e.g. textures, scenes, text files, etc), nor is it triggered when files are added/removed/renamed. As such there is no way for the plugin to know when stuff has changed unless the plugin compares the current state with what it knows was the last state. This however would involve scanning the whole project and therefore would already incur the cost of updating the resource groups anyways.

So I think a good solution would be to:

  1. only run the update on build rather than on save (it only needs to be done before the game is started, not on every save).
  2. add a project setting that disables the auto-update but keep it enabled by default, so it's an opt-out mechanism.

Would that work for you?

skison commented 2 months ago

Yes, thank you, this is just what I needed! I think it is a smart approach to make the auto-save opt-out for the reason you mentioned.

The project I'm working on has 3,947 files and 1,923 folders. Without the plugin enabled, saving takes approximately .4 seconds to complete, whereas with it enabled (the previous version before the one you just released) it takes approximately .75 seconds. Not a lot for a single save, but it adds up quick when you do it a lot.

With the new version, saving is just as snappy as before! I'm impressed with the super quick turnaround on this enhancement, thanks again!

derkork commented 2 months ago

Awesome, glad to hear it worked out! Let me know if you have additional ideas for improvement!