Generate interpolator settings from InterpolatorType enum

This commit is contained in:
johni0702
2017-01-28 10:51:24 +01:00
parent 6095aef3d1
commit 5cbfd2884e
2 changed files with 14 additions and 11 deletions

View File

@@ -2,22 +2,24 @@ package com.replaymod.simplepathing;
import com.replaymod.core.SettingsRegistry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
public final class Setting<T> extends SettingsRegistry.SettingKeys<T> {
public static final Setting<Boolean> PATH_PREVIEW = make("pathpreview", "pathpreview", true);
public static final SettingsRegistry.MultipleChoiceSettingKeys<String> DEFAULT_INTERPOLATION =
new SettingsRegistry.MultipleChoiceSettingKeys<>(
"simplepathing", "interpolator", "replaymod.gui.settings.interpolator",
"replaymod.gui.editkeyframe.interpolator.cubic.name");
public static final SettingsRegistry.MultipleChoiceSettingKeys<String> DEFAULT_INTERPOLATION;
static {
DEFAULT_INTERPOLATION.setChoices(new ArrayList<String>() {
{
add("replaymod.gui.editkeyframe.interpolator.cubic.name");
add("replaymod.gui.editkeyframe.interpolator.linear.name");
}
});
String format = "replaymod.gui.editkeyframe.interpolator.%s.name";
DEFAULT_INTERPOLATION = new SettingsRegistry.MultipleChoiceSettingKeys<>(
"simplepathing", "interpolator", "replaymod.gui.settings.interpolator",
String.format(format, InterpolatorType.fromString("invalid returns default").getLocalizationKey())
);
DEFAULT_INTERPOLATION.setChoices(
Arrays.stream(InterpolatorType.values()).filter(i -> i != InterpolatorType.DEFAULT)
.map(i -> String.format(format, i.getLocalizationKey()))
.collect(Collectors.toList())
);
}
private static <T> Setting<T> make(String key, String displayName, T defaultValue) {