Search in sources :

Example 1 with OptionalBoolean

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);
    });
}
Also used : OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean)

Example 2 with OptionalBoolean

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;
}
Also used : OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AbsolutePackPath(net.coderbot.iris.shaderpack.include.AbsolutePackPath) Set(java.util.Set) HashMap(java.util.HashMap) ParsedString(net.coderbot.iris.shaderpack.parsing.ParsedString) IntList(it.unimi.dsi.fastutil.ints.IntList) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) OptionValues(net.coderbot.iris.shaderpack.option.values.OptionValues) Pattern(java.util.regex.Pattern) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) LineTransform(net.coderbot.iris.shaderpack.transform.line.LineTransform) OptionalBoolean(net.coderbot.iris.shaderpack.OptionalBoolean)

Aggregations

OptionalBoolean (net.coderbot.iris.shaderpack.OptionalBoolean)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 AbsolutePackPath (net.coderbot.iris.shaderpack.include.AbsolutePackPath)1 OptionValues (net.coderbot.iris.shaderpack.option.values.OptionValues)1 ParsedString (net.coderbot.iris.shaderpack.parsing.ParsedString)1 LineTransform (net.coderbot.iris.shaderpack.transform.line.LineTransform)1