Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom dependencies #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

UserTeemu
Copy link
Contributor

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.

*/
fun setAsDependency(dependencyField: Field) {
propertyCollector.getProperty(dependencyField)!!.hasDependants = true
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of having separate methods for creating the dependency and then stating which field/property it depends on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you add a custom dependency, it doesn't need to be based on a property. For example, you could make a property be displayed only when you're connected to a certain server.
setAsDependency tells Vigilance to re-evaluate the visibility when the dependency property has changed. If setAsDependency hasn't been called, Vigilance will assume that the dependency doesn't care about any other properties.

Now that I think more about it, it would probably also be possible for addCustomDependency functions to have the dependency field as an optional argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants