EssentialGG / Vigilance

Configuration Utility using Elementa
GNU Lesser General Public License v3.0
54 stars 12 forks source link

Add custom dependencies #25

Open UserTeemu opened 2 years ago

UserTeemu commented 2 years ago

I asked for opinions about this concept earlier in the Discord server, but got no response. I decided to open a PR, so this doesn't get missed/forgotten. I am open to suggestions on this.

Short explaination about what this PR adds: Dependencies don't have to be based on boolean property states. Dependencies can be based on any function that returns a boolean. Properties may depend on a specific state of another property (not limited to boolean values). They can also depend on a completely external thing that isn't even a part of the config.

From the perspective of a mod dev, the changes in this PR don't change the behavior or usage of normal boolean property based dependencies, and instead just adds more options for making dependencies. However there are some changes under the hood.

A practical use case for this: In a config I am developing, I want to have a (dropdown) selector that chooses one mode for an animation. After that config property, I would like to have settings relevant to that selected mode. In other words, I want to hide all settings that aren't related to the selected mode.

I could set the mode-specific settings to depend on the mode chooser, but the issue is that normally Vigilance dependencies only support boolean properties (a selector isn't one of them, because there can be more than 2 options) as the dependencies.

With something like the changes in this PR, I could specify the conditions when to display a property based on whatever I want.