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

Backport 1.12.2 config subcategory behavior #58

Merged
merged 11 commits into from
Sep 1, 2024
Merged

Conversation

Lyfts
Copy link
Member

@Lyfts Lyfts commented Aug 31, 2024

In 1.12.2 you can declare static instances of inner classes in your @Config annotated class, those instances will then be automatically treated and parsed as subcategories of that class.

There's an example of it here https://github.com/GTNewHorizons/GTNHLib/blob/056959f0f51e3f2699274d264a9a7887a257f315/src/main/java/com/gtnewhorizon/gtnhlib/config/TestConfig.java

This will automagically be parsed into

# Configuration file

test {
    # This is a test boolean [default: true]
    B:testBoolean=true

    # This is a test double [range: 4.9E-324 ~ 1.7976931348623157E308, default: 1.0]
    D:testDouble=1.0

    # This is a test enum
    # Possible values: [TEST1, TEST2, TEST3]
    #  [default: TEST1]
    S:testEnum=TEST1

    # This is a test int [range: -2147483648 ~ 2147483647, default: 1]
    I:testInt=1

    ##########################################################################################################
    # subconfig
    #--------------------------------------------------------------------------------------------------------#
    # This is a sub config
    ##########################################################################################################

    subconfig {
        # This is a test boolean [default: true]
        B:testBoolean=true

        # This is a test double [range: 4.9E-324 ~ 1.7976931348623157E308, default: 1.0]
        D:testDouble=1.0

        # This is a test enum
        # Possible values: [TEST1, TEST2, TEST3]
        #  [default: TEST1]
        S:testEnum=TEST1

        # This is a test int [range: -2147483648 ~ 2147483647, default: 1]
        I:testInt=1

        ##########################################################################################################
        # doublesubconfig
        #--------------------------------------------------------------------------------------------------------#
        # This is a nested sub config
        ##########################################################################################################

        doublesubconfig {
            # This is a test boolean [default: true]
            B:testBoolean=true

            # This is a test double [range: 4.9E-324 ~ 1.7976931348623157E308, default: 1.0]
            D:testDouble=1.0

            # This is a test enum
            # Possible values: [TEST1, TEST2, TEST3]
            #  [default: TEST1]
            S:testEnum=TEST1

            # This is a test int [range: -2147483648 ~ 2147483647, default: 1]
            I:testInt=1
        }

    }

}

I also made it possible to get categorized IConfigElements for the config gui so that it will look like this

gtnhlib_conf

As opposed to something like Hodgepodge's current config gui where all the elements are on one page with a humongous scrollbar.

Also adds a method to save the current field values to the config file & adds double as a config option, because why tf is double[] an option while double isn't

@Lyfts Lyfts requested a review from a team August 31, 2024 19:09
@Caedis
Copy link
Member

Caedis commented Aug 31, 2024

Think its time to refactor processConfigInternal

Maybe add a method to the annotations so they the logic is there and we just pass it whatever it needs

If thats possible

@boubou19 boubou19 merged commit d1714b9 into master Sep 1, 2024
1 check passed
@boubou19 boubou19 deleted the config-subcategory branch September 1, 2024 18:09
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.

3 participants