use of net.coderbot.iris.shaderpack.OptionalBoolean in project Iris by IrisShaders.
the class MutableOptionValues method addAll.
public void addAll(Map<String, String> values) {
options.getBooleanOptions().forEach((name, option) -> {
String value = values.get(name);
OptionalBoolean booleanValue;
if (value == null) {
return;
}
if (value.equals("false")) {
booleanValue = OptionalBoolean.FALSE;
} else if (value.equals("true")) {
booleanValue = OptionalBoolean.TRUE;
} else {
// Invalid value specified, ignore it
// TODO: Diagnostic message?
booleanValue = OptionalBoolean.DEFAULT;
}
boolean actualValue = booleanValue.orElse(option.getOption().getDefaultValue());
if (actualValue == option.getOption().getDefaultValue()) {
// Just set it to default by removing it from the map
booleanValues.remove(name);
return;
}
booleanValues.put(name, actualValue);
});
options.getStringOptions().forEach((name, option) -> {
String value = values.get(name);
if (value == null) {
return;
}
if (value.equals(option.getOption().getDefaultValue())) {
stringValues.remove(name);
return;
}
stringValues.put(name, value);
});
}
use of net.coderbot.iris.shaderpack.OptionalBoolean in project Iris by IrisShaders.
the class OptionAnnotatedSource method edit.
private String edit(OptionValues values, int index, String existing) {
// See if it's a boolean option
BooleanOption booleanOption = booleanOptions.get(index);
if (booleanOption != null) {
OptionalBoolean value = values.getBooleanValue(booleanOption.getName());
if (booleanOption.getType() == OptionType.DEFINE) {
return setBooleanDefineValue(existing, value, booleanOption.getDefaultValue());
} else if (booleanOption.getType() == OptionType.CONST) {
if (value != OptionalBoolean.DEFAULT) {
// Value will never be default here, but we're using orElse just to get a normal boolean out of it.
return editConst(existing, Boolean.toString(booleanOption.getDefaultValue()), Boolean.toString(value.orElse(booleanOption.getDefaultValue())));
} else {
return existing;
}
} else {
throw new AssertionError("Unknown option type " + booleanOption.getType());
}
}
StringOption stringOption = stringOptions.get(index);
if (stringOption != null) {
return values.getStringValue(stringOption.getName()).map(value -> {
if (stringOption.getType() == OptionType.DEFINE) {
return "#define " + stringOption.getName() + " " + value + " // OptionAnnotatedSource: Changed option";
} else if (stringOption.getType() == OptionType.CONST) {
return editConst(existing, stringOption.getDefaultValue(), value);
} else {
throw new AssertionError("Unknown option type " + stringOption.getType());
}
}).orElse(existing);
}
return existing;
}
Aggregations