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

Default string representation for enum variants #79

Open
Goby56 opened this issue Dec 27, 2024 · 1 comment
Open

Default string representation for enum variants #79

Goby56 opened this issue Dec 27, 2024 · 1 comment

Comments

@Goby56
Copy link

Goby56 commented Dec 27, 2024

Now, I don't know if this already is possible but I couldn't find any example or documentation stating it is possible.

YACL provides something similar where if you have a enum that doesn't have a translation for it's variants it just uses the enum variant name as a translation instead of the whole translation key.

For example:
Using the enum

public enum Color {
    RED,
    GREEN,
    BLUE
}

would mean Midnightlib would put modid.midnightconfig.enum.Color.X for the option values in the GUI.

When you have alot of variants that you don't bother giving a translation to it would be much better if Midnightlib would put only the variant name as a default. Maybe this could be a toggle like useDefualtName when you specify it as a config entry.

This would instead produce the strings RED, GREEN and BLUE as values showing up in the GUI when cycling through the num option.

Additionally a custom string could be used if you, for example, extend the mojang StringIdentifiable class and implement the asString method. This would enable you to automize the translation process (atleast into a single language) by turning the enum variants in-code name to a more readable string representation. You could for example turn an enum variant such as DARK_BLUE into the string Dark Blue and have that show up in the GUI.

@Motschen
Copy link
Member

I could probably just use the enum variable name if no translation is loaded for it. Should be pretty easy and not take too much space. Thanks for this suggestion!
Though I probably won't implement the StringIdentifiable support, as it'd require the use of a lot of reflection, and would probably not be used by that many people.

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

No branches or pull requests

2 participants