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 support for config option update listener #87

Closed
wants to merge 12 commits into from

Conversation

P0keDev
Copy link
Member

@P0keDev P0keDev commented Jun 5, 2022

Classes with config options must now implement the Configurable interface, which contains an onUpdate() method that gets called any time a config value changes. It's also called when the class is first loaded, to make sure the method runs at least once even if all the contained options are set to default.

import com.wynntils.core.features.UserFeature;
import com.wynntils.core.features.properties.FeatureInfo;
import com.wynntils.core.features.properties.FeatureInfo.Stability;
import com.wynntils.core.webapi.WebManager;

@FeatureInfo(stability = Stability.STABLE)
@Configurable(category = "Item Tooltips")
@ConfigurableInfo(category = "Item Tooltips")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about making categories string constant in some files? What if we would want to change Item Tooltips to whatever new name and you would need to do that manually (or using IDE's find and replace). I think something like Categories.ITEM_TOOLTIPS would fit here better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, this won't be a problem if we use translations for config stuff.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Further tracked in #94.

Copy link
Member

Choose a reason for hiding this comment

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

Even if we use translations, I think it makes sense to have this an enum or a const defined in a class. It just makes it easier to make sure a typo don't ruin things, or do quickly go to all members of the category from the IDE. In general, using "raw" strings like this is not a good idea.

Copy link
Member

@magicus magicus left a comment

Choose a reason for hiding this comment

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

At the very least, change the callback method name and argument.


/** This handles the user enabling/disabling a feature in-game */
@Override
public void onConfigUpdate(ConfigOptionHolder option) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you need to check if the current option is the enabled one?
Either that or I don't get something about this method

Copy link
Member Author

Choose a reason for hiding this comment

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

This will run every time an update happens, yes, but tryEnable and tryDisable don't do anything if the feature is already in the correct state. I can add a check for the field's name though

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would we try to enable a feature by changing an unrelated setting?

Also, if it is not user enabled, why do we try to disable it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because if it's not user enabled, the feature is supposed to be disabled

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't respect the condition system in place

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like the super calls will absolutely be forgotten when actually writing code, although I can't think of something better atm.

Copy link
Member Author

Choose a reason for hiding this comment

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

The javax library contains the annotation @OverridingMethodMustInvokeSuper, which raises an error if the super method isn't called. We should be able to use this for peace of mind

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, looks like the annotation isn't fully implemented - although it will still cause a warning in intellij

Copy link
Collaborator

Choose a reason for hiding this comment

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

Warning should be enough

Copy link
Member

Choose a reason for hiding this comment

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

Once again, I'm not convinced the "turn feature on or off" thing really should be a config like the others. It could just as well be seen as configurations on the FeatureRegistry. It has a bit of an odd ring to it, that a feature is configured to turn itself on or off. I can very much imagine a GUI where the "on/off" functionality of a feature is shown by a switch or checkbox next to the feature name in a list, but the configuration variables for that feature is shown on a config pane to the right of the list. Like the common model for how you enable/disable mods/plugins etc in one place, but configure them elsewhere.

Especially if this switch is making the "real" configuration options more complicated, by forcing the use of a super() call. I think this is a sign that feature-enabled is a property that should have special treatment, and not be considered a general config option.

Copy link
Contributor

@Incompleteusern Incompleteusern left a comment

Choose a reason for hiding this comment

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

It'd be nice for the config listener needed for itemGuessFeature to be implemented here

@P0keDev
Copy link
Member Author

P0keDev commented Jun 6, 2022

what config listener does the item guess feature need?

@Incompleteusern
Copy link
Contributor

It was mentioned in the previous config pr, but it needs to load the relevant web api for showGuessPrice

@P0keDev
Copy link
Member Author

P0keDev commented Jun 6, 2022

why does that need an additional config listener? it's already handled by the feature's condition and its onEnable method

@Incompleteusern
Copy link
Contributor

It needs to make sure that the itemlist api is loaded, which is solely dependent on showGuessPrice being true.

@P0keDev P0keDev closed this Jun 6, 2022
@magicus
Copy link
Member

magicus commented Jun 6, 2022

@P0keDev Why did you close this?

@P0keDev
Copy link
Member Author

P0keDev commented Jun 6, 2022

i no longer have motivation to work on this, it would be best for someone else to pick it up

@magicus
Copy link
Member

magicus commented Jun 6, 2022

Oh, that's too bad. :-( I think this was right on track...

@P0keDev P0keDev deleted the config-on-update branch June 17, 2022 09:12
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.

None yet

4 participants