Skip to content

Commit 7a99a2e

Browse files
committed
Fix smooth volume labeling in config, off state serialization
The labels were off by a factor of 100, and the feature being off was saved as a speed of 10000% instead of a usual sentinel value such as -1 (which it is now).
1 parent 1482e9b commit 7a99a2e

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

platforms/common/src/main/java/dynamic_fps/impl/compat/ClothConfig.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static Screen genConfigScreen(Screen parent) {
101101
entryBuilder.startIntSlider(
102102
localized("config", "volume_transition_speed_up"),
103103
volumeTransformer.toStep((int) (DynamicFPSMod.volumeTransitionSpeed().getUp() * 10)),
104-
1, 31
104+
1, 13
105105
)
106106
.setDefaultValue(volumeTransformer.toStep((int) (defaultConfig.volumeTransitionSpeed().getUp() * 10)))
107107
.setSaveConsumer(step -> DynamicFPSMod.volumeTransitionSpeed().setUp((float) volumeTransformer.toValue(step) / 10))
@@ -114,7 +114,7 @@ public static Screen genConfigScreen(Screen parent) {
114114
entryBuilder.startIntSlider(
115115
localized("config", "volume_transition_speed_down"),
116116
volumeTransformer.toStep((int) (DynamicFPSMod.volumeTransitionSpeed().getDown() * 10)),
117-
1, 31
117+
1, 13
118118
)
119119
.setDefaultValue(volumeTransformer.toStep((int) (defaultConfig.volumeTransitionSpeed().getDown() * 10)))
120120
.setSaveConsumer(step -> DynamicFPSMod.volumeTransitionSpeed().setDown((float) volumeTransformer.toValue(step) / 10))
@@ -309,16 +309,19 @@ private static Component idleTimeMessage(int value) {
309309
private static VariableStepTransformer getVolumeStepTransformer() {
310310
VariableStepTransformer transformer = new VariableStepTransformer();
311311

312-
transformer.addStep(1, 30);
313-
transformer.addStep(970, 1000);
312+
// Since the transformer only works with integers
313+
// We multiply the percentage by 10 to work with it
314+
transformer.addStep(1, 10);
315+
transformer.addStep(10, 30);
316+
transformer.addStep(70, 100);
314317

315318
return transformer;
316319
}
317320

318321
private static Component volumeTransitionMessage(int step) {
319-
float value = (float) getVolumeStepTransformer().toValue(step) / 10;
322+
int value = getVolumeStepTransformer().toValue(step) * 10;
320323

321-
if (value < 100.0f) {
324+
if (value <= 300) {
322325
return Component.literal(value + "%");
323326
} else {
324327
return localized("config", "volume_transition_speed_instant");

platforms/common/src/main/java/dynamic_fps/impl/config/VolumeTransitionConfig.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,46 @@ public class VolumeTransitionConfig {
44
private float up;
55
private float down;
66

7+
private static final float IMMEDIATE = 10.0f;
8+
79
protected VolumeTransitionConfig(float up, float down) {
810
this.up = up;
911
this.down = down;
1012
}
1113

1214
public float getUp() {
13-
return this.up;
15+
if (this.up == -1) {
16+
return IMMEDIATE;
17+
} else {
18+
return this.up;
19+
}
1420
}
1521

1622
public void setUp(float value) {
17-
this.up = value;
23+
if (value >= IMMEDIATE) {
24+
this.up = -1.0f;
25+
} else {
26+
this.up = value;
27+
}
1828
}
1929

2030
public float getDown() {
21-
return this.down;
31+
if (this.down == -1) {
32+
return IMMEDIATE;
33+
} else {
34+
return this.down;
35+
}
2236
}
2337

2438
public void setDown(float value) {
25-
this.down = value;
39+
if (value >= IMMEDIATE) {
40+
this.down = -1.0f;
41+
} else {
42+
this.down = value;
43+
}
2644
}
2745

2846
public boolean isActive() {
29-
return this.up != 100.0f || this.down != 100.0f;
47+
return this.up != -1.0f || this.down != -1.0f;
3048
}
3149
}

0 commit comments

Comments
 (0)