Skip to content

Commit

Permalink
Remove chained config creation for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Oct 5, 2023
1 parent d13b27f commit d771566
Showing 1 changed file with 64 additions and 48 deletions.
112 changes: 64 additions & 48 deletions src/main/java/dynamic_fps/impl/compat/ClothConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

public final class ClothConfig {
public static Screen genConfigScreen(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create()
var builder = ConfigBuilder.create()
.setParentScreen(parent)
.setTitle(localized("config", "title"))
.setSavingRunnable(DynamicFPSMod.modConfig::save);

ConfigEntryBuilder entryBuilder = builder.entryBuilder();
var entryBuilder = builder.entryBuilder();

for (var state : PowerState.values()) {
if (!state.configurable) {
Expand All @@ -32,52 +32,68 @@ public static Screen genConfigScreen(Screen parent) {
var config = DynamicFPSMod.modConfig.get(state);
var standard = DynamicFPSConfig.getDefaultConfig(state);

builder.getOrCreateCategory(
localized("config", "category." + state.toString().toLowerCase()))
.addEntry(entryBuilder
.startIntSlider(
localized("config", "frame_rate_target"),
fromConfigFpsTarget(config.frameRateTarget()),
0, 61)
.setDefaultValue(fromConfigFpsTarget(standard.frameRateTarget()))
.setSaveConsumer(value -> config.setFrameRateTarget(toConfigFpsTarget(value)))
.setTextGetter(ClothConfig::fpsTargetMessage)
.build())
.addEntry(entryBuilder
.startIntSlider(
localized("config", "volume_multiplier"),
(int) (config.volumeMultiplier() * 100),
0, 100)
.setDefaultValue((int) (standard.volumeMultiplier() * 100))
.setSaveConsumer(value -> config.setVolumeMultiplier(value / 100f))
.setTextGetter(ClothConfig::volumeMultiplierMessage)
.build())
.addEntry(entryBuilder
.startEnumSelector(
localized("config", "graphics_state"),
GraphicsState.class,
config.graphicsState())
.setDefaultValue(standard.graphicsState())
.setSaveConsumer(config::setGraphicsState)
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
.build())
.addEntry(entryBuilder
.startBooleanToggle(
localized("config", "show_toasts"),
config.showToasts())
.setDefaultValue(standard.showToasts())
.setSaveConsumer(config::setShowToasts)
.setTooltip(localized("config", "show_toasts_tooltip"))
.build())
.addEntry(entryBuilder
.startBooleanToggle(
localized("config", "run_garbage_collector"),
config.runGarbageCollector())
.setDefaultValue(standard.runGarbageCollector())
.setSaveConsumer(config::setRunGarbageCollector)
.setTooltip(localized("config", "run_garbage_collector_tooltip"))
.build());
var category = builder.getOrCreateCategory(
localized("config", "category." + state.toString().toLowerCase())
);

category.addEntry(
entryBuilder.startIntSlider(
localized("config", "frame_rate_target"),
fromConfigFpsTarget(config.frameRateTarget()),
0, 61
)
.setDefaultValue(fromConfigFpsTarget(standard.frameRateTarget()))
.setSaveConsumer(value -> config.setFrameRateTarget(toConfigFpsTarget(value)))
.setTextGetter(ClothConfig::fpsTargetMessage)
.build()
);

category.addEntry(
entryBuilder.startIntSlider(
localized("config", "volume_multiplier"),
(int) (config.volumeMultiplier() * 100),
0, 100
)
.setDefaultValue((int) (standard.volumeMultiplier() * 100))
.setSaveConsumer(value -> config.setVolumeMultiplier(value / 100f))
.setTextGetter(ClothConfig::volumeMultiplierMessage)
.build()
);

category.addEntry(
entryBuilder.startEnumSelector(
localized("config", "graphics_state"),
GraphicsState.class,
config.graphicsState()
)
.setDefaultValue(standard.graphicsState())
.setSaveConsumer(config::setGraphicsState)
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
.build()
);

category.addEntry(
entryBuilder.startBooleanToggle(
localized("config", "show_toasts"),
config.showToasts()
)
.setDefaultValue(standard.showToasts())
.setSaveConsumer(config::setShowToasts)
.setTooltip(localized("config", "show_toasts_tooltip"))
.build()
);

category.addEntry(
entryBuilder.startBooleanToggle(
localized("config", "run_garbage_collector"),
config.runGarbageCollector()
)
.setDefaultValue(standard.runGarbageCollector())
.setSaveConsumer(config::setRunGarbageCollector)
.setTooltip(localized("config", "run_garbage_collector_tooltip"))
.build()
);
}

return builder.build();
Expand Down

0 comments on commit d771566

Please sign in to comment.