aboutsummaryrefslogtreecommitdiff
path: root/src/client/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/java')
-rw-r--r--src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java15
-rw-r--r--src/client/java/dev/isxander/yacl/api/utils/Dimension.java33
-rw-r--r--src/client/java/dev/isxander/yacl/api/utils/MutableDimension.java11
-rw-r--r--src/client/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java115
-rw-r--r--src/client/java/dev/isxander/yacl/impl/utils/YACLConstants.java8
5 files changed, 15 insertions, 167 deletions
diff --git a/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java b/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java
index a69ae4e..ae6c060 100644
--- a/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java
+++ b/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java
@@ -1,6 +1,7 @@
package dev.isxander.yacl.api;
import com.google.common.collect.ImmutableList;
+import dev.isxander.yacl.config.ConfigInstance;
import dev.isxander.yacl.gui.YACLScreen;
import dev.isxander.yacl.impl.YetAnotherConfigLibImpl;
import net.minecraft.client.gui.screen.Screen;
@@ -12,6 +13,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
/**
@@ -53,6 +55,14 @@ public interface YetAnotherConfigLib {
return new Builder();
}
+ /**
+ * Creates an instance using a {@link ConfigInstance} which autofills the save() builder method.
+ * This also takes an easy functional interface that provides defaults and config to help build YACL bindings.
+ */
+ static <T> YetAnotherConfigLib create(ConfigInstance<T> configInstance, ConfigBackedBuilder<T> builder) {
+ return builder.build(configInstance.getDefaults(), configInstance.getConfig(), createBuilder().save(configInstance::save)).build();
+ }
+
class Builder {
private Text title;
private final List<ConfigCategory> categories = new ArrayList<>();
@@ -133,4 +143,9 @@ public interface YetAnotherConfigLib {
return new YetAnotherConfigLibImpl(title, ImmutableList.copyOf(categories), saveFunction, initConsumer);
}
}
+
+ @FunctionalInterface
+ interface ConfigBackedBuilder<T> {
+ YetAnotherConfigLib.Builder build(T defaults, T config, YetAnotherConfigLib.Builder builder);
+ }
}
diff --git a/src/client/java/dev/isxander/yacl/api/utils/Dimension.java b/src/client/java/dev/isxander/yacl/api/utils/Dimension.java
deleted file mode 100644
index 0de0a58..0000000
--- a/src/client/java/dev/isxander/yacl/api/utils/Dimension.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package dev.isxander.yacl.api.utils;
-
-import dev.isxander.yacl.impl.utils.DimensionIntegerImpl;
-
-public interface Dimension<T extends Number> {
- T x();
- T y();
-
- T width();
- T height();
-
- T xLimit();
- T yLimit();
-
- T centerX();
- T centerY();
-
- boolean isPointInside(T x, T y);
-
- MutableDimension<T> clone();
-
- Dimension<T> withX(T x);
- Dimension<T> withY(T y);
- Dimension<T> withWidth(T width);
- Dimension<T> withHeight(T height);
-
- Dimension<T> moved(T x, T y);
- Dimension<T> expanded(T width, T height);
-
- static MutableDimension<Integer> ofInt(int x, int y, int width, int height) {
- return new DimensionIntegerImpl(x, y, width, height);
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/api/utils/MutableDimension.java b/src/client/java/dev/isxander/yacl/api/utils/MutableDimension.java
deleted file mode 100644
index eff0186..0000000
--- a/src/client/java/dev/isxander/yacl/api/utils/MutableDimension.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package dev.isxander.yacl.api.utils;
-
-public interface MutableDimension<T extends Number> extends Dimension<T> {
- MutableDimension<T> setX(T x);
- MutableDimension<T> setY(T y);
- MutableDimension<T> setWidth(T width);
- MutableDimension<T> setHeight(T height);
-
- MutableDimension<T> move(T x, T y);
- MutableDimension<T> expand(T width, T height);
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java b/src/client/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java
deleted file mode 100644
index 6c7508d..0000000
--- a/src/client/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package dev.isxander.yacl.impl.utils;
-
-import dev.isxander.yacl.api.utils.Dimension;
-import dev.isxander.yacl.api.utils.MutableDimension;
-
-public class DimensionIntegerImpl implements MutableDimension<Integer> {
- private int x, y;
- private int width, height;
-
- public DimensionIntegerImpl(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
- @Override
- public Integer x() {
- return x;
- }
-
- @Override
- public Integer y() {
- return y;
- }
-
- @Override
- public Integer width() {
- return width;
- }
-
- @Override
- public Integer height() {
- return height;
- }
-
- @Override
- public Integer xLimit() {
- return x + width;
- }
-
- @Override
- public Integer yLimit() {
- return y + height;
- }
-
- @Override
- public Integer centerX() {
- return x + width / 2;
- }
-
- @Override
- public Integer centerY() {
- return y + height / 2;
- }
-
- @Override
- public boolean isPointInside(Integer x, Integer y) {
- return x >= x() && x <= xLimit() && y >= y() && y <= yLimit();
- }
-
- @Override
- public MutableDimension<Integer> clone() {
- return new DimensionIntegerImpl(x, y, width, height);
- }
-
- @Override public MutableDimension<Integer> setX(Integer x) { this.x = x; return this; }
- @Override public MutableDimension<Integer> setY(Integer y) { this.y = y; return this; }
- @Override public MutableDimension<Integer> setWidth(Integer width) { this.width = width; return this; }
- @Override public MutableDimension<Integer> setHeight(Integer height) { this.height = height; return this; }
-
- @Override
- public Dimension<Integer> withX(Integer x) {
- return clone().setX(x);
- }
-
- @Override
- public Dimension<Integer> withY(Integer y) {
- return clone().setY(y);
- }
-
- @Override
- public Dimension<Integer> withWidth(Integer width) {
- return clone().setWidth(width);
- }
-
- @Override
- public Dimension<Integer> withHeight(Integer height) {
- return clone().setHeight(height);
- }
-
- @Override
- public MutableDimension<Integer> move(Integer x, Integer y) {
- this.x += x;
- this.y += y;
- return this;
- }
-
- @Override
- public MutableDimension<Integer> expand(Integer width, Integer height) {
- this.width += width;
- this.height += height;
- return this;
- }
-
- @Override
- public Dimension<Integer> moved(Integer x, Integer y) {
- return clone().move(x, y);
- }
-
- @Override
- public Dimension<Integer> expanded(Integer width, Integer height) {
- return clone().expand(width, height);
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/impl/utils/YACLConstants.java b/src/client/java/dev/isxander/yacl/impl/utils/YACLConstants.java
deleted file mode 100644
index 3d382d4..0000000
--- a/src/client/java/dev/isxander/yacl/impl/utils/YACLConstants.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package dev.isxander.yacl.impl.utils;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class YACLConstants {
- public static final Logger LOGGER = LoggerFactory.getLogger("YetAnotherConfigLib");
-}