Fix enum entries
This commit is contained in:
parent
08f6a9821b
commit
163b1524a8
|
@ -37,7 +37,16 @@ public class ConfigEnumEntry extends Entry<Integer> {
|
||||||
public boolean typeMatches(Entry<?> val) {
|
public boolean typeMatches(Entry<?> val) {
|
||||||
return val instanceof ConfigEnumEntry;
|
return val instanceof ConfigEnumEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendString(StringBuilder sb) {
|
||||||
|
sb.append(getValueName()).append('/').append(getValue()).append(" (").append(getDefaultName()).append('/').append(getDefault()).append(" of:");
|
||||||
|
for (Map.Entry<String, Integer> e : values.entrySet()) {
|
||||||
|
sb.append(' ').append(e.getKey()).append('/').append(e.getValue());
|
||||||
|
}
|
||||||
|
sb.append(')');
|
||||||
|
}
|
||||||
|
|
||||||
public void setFieldName(String s) {
|
public void setFieldName(String s) {
|
||||||
if (s != null)
|
if (s != null)
|
||||||
fieldName = s;
|
fieldName = s;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import io.gitlab.jfronny.respackopts.data.RpoError;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
//TODO implement equality checking for string/number variables
|
|
||||||
public class EqualityCondition implements Condition {
|
public class EqualityCondition implements Condition {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(JsonElement node) throws RpoError {
|
public boolean evaluate(JsonElement node) throws RpoError {
|
||||||
|
@ -15,7 +15,7 @@ public class EqualityCondition implements Condition {
|
||||||
Optional<Boolean> v = Optional.empty();
|
Optional<Boolean> v = Optional.empty();
|
||||||
for (JsonElement jsonElement : node.getAsJsonArray()) {
|
for (JsonElement jsonElement : node.getAsJsonArray()) {
|
||||||
boolean current = ConditionEvaluator.evaluate(jsonElement);
|
boolean current = ConditionEvaluator.evaluate(jsonElement);
|
||||||
if (!v.isPresent())
|
if (v.isEmpty())
|
||||||
v = Optional.of(current);
|
v = Optional.of(current);
|
||||||
if (current != v.get())
|
if (current != v.get())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,7 +21,6 @@ import net.minecraft.util.Language;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
//TODO fix enums always showing "reset" and not saving/loading properly from GUI
|
|
||||||
public class GuiFactory {
|
public class GuiFactory {
|
||||||
public void buildCategory(ConfigBranch source, String screenId, JfConfigCategory config, ConfigEntryBuilder entryBuilder, String namePrefix) {
|
public void buildCategory(ConfigBranch source, String screenId, JfConfigCategory config, ConfigEntryBuilder entryBuilder, String namePrefix) {
|
||||||
String b = "respackopts.field." + screenId;
|
String b = "respackopts.field." + screenId;
|
||||||
|
@ -43,8 +42,8 @@ public class GuiFactory {
|
||||||
}
|
}
|
||||||
else if (entry instanceof ConfigEnumEntry e) {
|
else if (entry instanceof ConfigEnumEntry e) {
|
||||||
config.addEntry(entryBuilder.startDropdownMenu(getText(n, b),
|
config.addEntry(entryBuilder.startDropdownMenu(getText(n, b),
|
||||||
DropdownMenuBuilder.TopCellElementBuilder.of(e.getValueName(), LiteralText::new),
|
DropdownMenuBuilder.TopCellElementBuilder.of(e.getValueName(), s -> s, LiteralText::new),
|
||||||
new DropdownBoxEntry.DefaultSelectionCellCreator())
|
new DropdownBoxEntry.DefaultSelectionCellCreator<>())
|
||||||
.setSuggestionMode(false)
|
.setSuggestionMode(false)
|
||||||
.setDefaultValue(e.getDefaultName())
|
.setDefaultValue(e.getDefaultName())
|
||||||
.setSelections(() -> e.values.keySet().iterator())
|
.setSelections(() -> e.values.keySet().iterator())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user