Skip to content

Commit e868c71

Browse files
authored
Fix integer formatting in autogen integer/long fields and sliders (#325)
* Fix integer formatting autogen integer fields and sliders * Add `testLongFormatted` to `MasterTickBox` values
1 parent cdd8cc6 commit e868c71

9 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/main/java/dev/isxander/yacl3/config/v2/api/autogen/IntField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737
* The format used to display the integer.
3838
* This is the syntax used in {@link String#format(String, Object...)}.
3939
*/
40-
String format() default "%.0f";
40+
String format() default "%d";
4141
}

src/main/java/dev/isxander/yacl3/config/v2/api/autogen/IntSlider.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@
2727
*/
2828
int max();
2929

30+
/**
31+
* The step size of this slider.
32+
* <p>
33+
* For example, if this is set to 1, the slider will
34+
* increment/decrement by 1 when dragging, no less, no more and
35+
* will always be a multiple of 1.
36+
*/
37+
int step();
38+
3039
/**
3140
* The format used to display the integer.
3241
* This is the syntax used in {@link String#format(String, Object...)}.
3342
*/
34-
int step();
43+
String format() default "%d";
3544
}

src/main/java/dev/isxander/yacl3/config/v2/api/autogen/LongField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737
* The format used to display the long.
3838
* This is the syntax used in {@link String#format(String, Object...)}.
3939
*/
40-
String format() default "%.0f";
40+
String format() default "%d";
4141
}

src/main/java/dev/isxander/yacl3/config/v2/api/autogen/LongSlider.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@
2828
long max();
2929

3030
/**
31-
* The format used to display the integer.
32-
* This is the syntax used in {@link String#format(String, Object...)}.
31+
* The step size of this slider.
32+
* <p>
33+
* For example, if this is set to 1, the slider will
34+
* increment/decrement by 1 when dragging, no less, no more and
35+
* will always be a multiple of 1.
3336
*/
3437
long step();
38+
39+
/**
40+
* The format used to display the long.
41+
* This is the syntax used in {@link String#format(String, Object...)}.
42+
*/
43+
String format() default "%d";
3544
}

src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntFieldImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected ControllerBuilder<Integer> createController(IntField annotation, Confi
2121
key = getTranslationKey(field, "fmt");
2222
if (Language.getInstance().has(key))
2323
return Component.translatable(key, v);
24-
return Component.literal(Integer.toString(v));
24+
return Component.literal(String.format(annotation.format(), v));
2525
})
2626
.range(annotation.min(), annotation.max());
2727
}

src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntSliderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected ControllerBuilder<Integer> createController(IntSlider annotation, Conf
2121
key = getTranslationKey(field, "fmt");
2222
if (Language.getInstance().has(key))
2323
return Component.translatable(key, v);
24-
return Component.literal(Integer.toString(v));
24+
return Component.literal(String.format(annotation.format(), v));
2525
})
2626
.range(annotation.min(), annotation.max())
2727
.step(annotation.step());

src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongFieldImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected ControllerBuilder<Long> createController(LongField annotation, ConfigF
2121
key = getTranslationKey(field, "fmt");
2222
if (Language.getInstance().has(key))
2323
return Component.translatable(key, v);
24-
return Component.literal(Long.toString(v));
24+
return Component.literal(String.format(annotation.format(), v));
2525
})
2626
.range(annotation.min(), annotation.max());
2727
}

src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongSliderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected ControllerBuilder<Long> createController(LongSlider annotation, Config
2121
key = getTranslationKey(field, "fmt");
2222
if (Language.getInstance().has(key))
2323
return Component.translatable(key, v);
24-
return Component.literal(Long.toString(v));
24+
return Component.literal(String.format(annotation.format(), v));
2525
})
2626
.range(annotation.min(), annotation.max())
2727
.step(annotation.step());

src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AutogenConfigTest {
3232
.build();
3333

3434
@AutoGen(category = "test", group = "master_test")
35-
@MasterTickBox({ "testTickBox", "testBoolean", "testInt", "testDouble", "testFloat", "testLong", "testIntField", "testDoubleField", "testFloatField", "testLongField", "testEnum", "testColor", "testString", "testDropdown", "testItem" })
35+
@MasterTickBox({ "testTickBox", "testBoolean", "testInt", "testDouble", "testFloat", "testLong", "testLongFormatted", "testIntField", "testDoubleField", "testFloatField", "testLongField", "testEnum", "testColor", "testString", "testDropdown", "testItem" })
3636
@SerialEntry(comment = "This option disables all the other options in this group")
3737
public boolean masterOption = true;
3838

@@ -64,6 +64,10 @@ public class AutogenConfigTest {
6464
@LongSlider(min = 0, max = 10, step = 2)
6565
@SerialEntry public long testLong = 0;
6666

67+
@AutoGen(category = "test", group = "master_test")
68+
@LongSlider(min = 0, max = 1000, step = 10, format = "%dms")
69+
@SerialEntry public long testLongFormatted = 500;
70+
6771
@AutoGen(category = "test", group = "master_test")
6872
@IntField(min = 0, max = 10)
6973
@SerialEntry public int testIntField = 0;

0 commit comments

Comments
 (0)