aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/dev/isxander/yacl3/api/utils
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/api/utils')
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/utils/Dimension.java33
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/utils/MutableDimension.java11
-rw-r--r--common/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java39
3 files changed, 83 insertions, 0 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/api/utils/Dimension.java b/common/src/main/java/dev/isxander/yacl3/api/utils/Dimension.java
new file mode 100644
index 0000000..ec09238
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl3/api/utils/Dimension.java
@@ -0,0 +1,33 @@
+package dev.isxander.yacl3.api.utils;
+
+import dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/utils/MutableDimension.java b/common/src/main/java/dev/isxander/yacl3/api/utils/MutableDimension.java
new file mode 100644
index 0000000..f551232
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl3/api/utils/MutableDimension.java
@@ -0,0 +1,11 @@
+package dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java b/common/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java
new file mode 100644
index 0000000..cf33f0f
--- /dev/null
+++ b/common/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java
@@ -0,0 +1,39 @@
+package dev.isxander.yacl3.api.utils;
+
+import dev.isxander.yacl3.api.*;
+
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+public class OptionUtils {
+ /**
+ * Consumes all options, ignoring groups and categories.
+ * When consumer returns true, this function stops iterating.
+ */
+ public static void consumeOptions(YetAnotherConfigLib yacl, Function<Option<?>, Boolean> consumer) {
+ for (ConfigCategory category : yacl.categories()) {
+ for (OptionGroup group : category.groups()) {
+ if (group instanceof ListOption<?> list) {
+ if (consumer.apply(list)) return;
+ } else {
+ for (Option<?> option : group.options()) {
+ if (consumer.apply(option)) return;
+ }
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Consumes all options, ignoring groups and categories.
+ *
+ * @see OptionUtils#consumeOptions(YetAnotherConfigLib, Function)
+ */
+ public static void forEachOptions(YetAnotherConfigLib yacl, Consumer<Option<?>> consumer) {
+ consumeOptions(yacl, (opt) -> {
+ consumer.accept(opt);
+ return false;
+ });
+ }
+}