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

ModDetectedDefault config annotation #65

Merged
merged 7 commits into from
Sep 2, 2024
Merged

Conversation

Lyfts
Copy link
Member

@Lyfts Lyfts commented Sep 2, 2024

Inspired by #26

This lovely test config https://github.com/GTNewHorizons/GTNHLib/blob/55582cbe9ba1c4cf6d22a4c904e5259a051a0c8a/src/main/java/com/gtnewhorizon/gtnhlib/config/TestConfig.java does correctly get parsed into the following while Hodgepodge is present

test {
    #  [default: false]
    B:testBoolean=false

    #  [default: true]
    B:testBooleanButCooler=true

    #  [range: 4.9E-324 ~ 1.7976931348623157E308, default: 3333.0]
    D:testDouble=3333.0

    #  [range: 4.9E-324 ~ 1.7976931348623157E308, default: 1.0]
    D:testDoubleButCooler=1.0

    # This is a test double list [default: [4.0, 5.0, 6.0]]
    D:testDoubleList <
        4.0
        5.0
        6.0
     >

    # This is a test double list (or not) [default: [1.0, 2.0, 3.0]]
    D:testDoubleListButCooler <
        1.0
        2.0
        3.0
     >

    # 
    # Possible values: [TEST1, TEST2, TEST3]
    #  [default: TEST2]
    S:testEnum=TEST2

    # 
    # Possible values: [TEST1, TEST2, TEST3]
    #  [default: TEST1]
    S:testEnumButCooler=TEST1

    #  [range: 1.4E-45 ~ 3.4028235E38, default: 3333.0]
    S:testFloat=3333.0

    #  [range: 1.4E-45 ~ 3.4028235E38, default: 1.0]
    S:testFloatButCooler=1.0

    #  [range: -2147483648 ~ 2147483647, default: 3333]
    I:testInt=3333

    #  [range: -2147483648 ~ 2147483647, default: 1]
    I:testIntButCooler=1

    # This is a test int list [default: [4, 5, 6]]
    I:testIntList <
        4
        5
        6
     >

    # This is a test int list [default: [1, 2, 3]]
    I:testIntListButCooler <
        1
        2
        3
     >

    #  [default: STRING]
    S:testString=STRING

    #  [default: STRING]
    S:testStringButCooler=STRING

    # This is a test string list [default: [test4], [test5], [test6]]
    S:testStringList <
        test4
        test5
        test6
     >

    # This is a test string list (or not) [default: [test1], [test2], [test3]]
    S:testStringListButCooler <
        test1
        test2
        test3
     >
}

I also added a ModDetectedDefaultList which accepts multiple ModDetectedDefaults in case several defaults are desired for different mods, it will always use the value of the first mod it finds in the list.

@Lyfts Lyfts requested review from Caedis and a team September 2, 2024 12:53
@Caedis
Copy link
Member

Caedis commented Sep 2, 2024

Great work!
What is the purpose of the `@SneakyThrow`s?

@Lyfts
Copy link
Member Author

Lyfts commented Sep 2, 2024

I found it exceptionally annoying to read through the parsers with the very large amount of exceptions that had to be added to the various methods throws declaration.
The Exceptions that can be thrown doesn't really matter here as all caught exceptions are repackaged into a ConfigException that describes which field it failed at along with the original exception.

@Caedis
Copy link
Member

Caedis commented Sep 2, 2024

Gotcha, so it basically fakes the throws list for the compiler

@Dream-Master Dream-Master merged commit 0ec72e9 into master Sep 2, 2024
1 check passed
@Dream-Master Dream-Master deleted the mod-detected-default branch September 2, 2024 15:00
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