Skip to content

Commit

Permalink
reduce the api surface of QuarkConfigBuilder a little more
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 23, 2023
1 parent 790b795 commit 4a038de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public interface IConfigBuilder {
void pop();
void comment(String s);

ForgeConfigSpec.ConfigValue<List<?>> defineList(String name, List<?> default_, Supplier<List<?>> getter, Predicate<Object> predicate);
ForgeConfigSpec.ConfigValue<?> defineObj(String name, Object default_, Supplier<Object> getter, Predicate<Object> predicate);
<T> ForgeConfigSpec.ConfigValue<List<? extends T>> defineList(String name, List<? extends T> default_, Supplier<List<? extends T>> getter, Predicate<Object> predicate);
<T> ForgeConfigSpec.ConfigValue<T> defineObj(String name, T default_, Supplier<T> getter, Predicate<Object> predicate);

default ForgeConfigSpec.ConfigValue<Boolean> defineBool(String name, Supplier<Boolean> getter, boolean default_) {
return defineObj(name, default_, getter, x -> true);
}

ForgeConfigSpec.ConfigValue<Boolean> defineBool(String name, Supplier<Boolean> getter, boolean default_);
ForgeConfigSpec.ConfigValue<Integer> defineInt(String name, Supplier<Integer> getter, int default_);
ForgeConfigSpec.ConfigValue<Double> defineDouble(String name, Supplier<Double> getter, double default_);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public void comment(String s) {
}

@Override
public ConfigValue<List<?>> defineList(String name, List<?> default_, Supplier<List<?>> getter, Predicate<Object> predicate) {
public <T> ConfigValue<List<? extends T>> defineList(String name, List<? extends T> default_, Supplier<List<? extends T>> getter, Predicate<Object> predicate) {
beforeDefine();
ConfigValue<List<?>> value = parent.defineList(name, default_, predicate);
ConfigValue<List<? extends T>> value = parent.defineList(name, default_, predicate);
onDefine(value, default_, getter, predicate);
return value;
}

@Override
public ConfigValue<?> defineObj(String name, Object default_, Supplier<Object> getter, Predicate<Object> predicate) {
public <T> ConfigValue<T> defineObj(String name, T default_, Supplier<T> getter, Predicate<Object> predicate) {
if(default_ == null)
throw new RuntimeException("Can't define object " + name + " with null default @ " + layers.toString());

beforeDefine();
ConfigValue<Object> value = parent.define(name, default_, predicate);
ConfigValue<T> value = parent.define(name, default_, predicate);
onDefine(value, default_, getter, predicate);
return value;
}
Expand All @@ -74,24 +74,8 @@ public ConfigValue<Boolean> defineBool(String name, Supplier<Boolean> getter, bo
return value;
}

@Override
public ConfigValue<Integer> defineInt(String name, Supplier<Integer> getter, int default_) {
beforeDefine();
ConfigValue<Integer> value = parent.define(name, default_);
onDefine(value, default_, getter, o -> true);
return value;
}

@Override
public ConfigValue<Double> defineDouble(String name, Supplier<Double> getter, double default_) {
beforeDefine();
ConfigValue<Double> value = parent.define(name, default_);
onDefine(value, default_, getter, o -> true);
return value;
}

private void beforeDefine() {
if(currComment.length() > 0)
if(!currComment.isEmpty())
parent.comment(currComment);
}

Expand Down

0 comments on commit 4a038de

Please sign in to comment.