diff options
author | isXander <xander@isxander.dev> | 2023-08-16 12:56:15 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2023-08-16 12:56:15 +0100 |
commit | 98f29ec5c30d23999fce37d7daf7aba8f10f25d3 (patch) | |
tree | 95cfa91eff48330072f8d50109b594bc16c4c9f0 /common/src/main/java/dev/isxander/yacl3/impl | |
parent | b3d5164010682cdf2d3f68be141792bf71a5dd49 (diff) | |
download | YetAnotherConfigLib-98f29ec5c30d23999fce37d7daf7aba8f10f25d3.tar.gz YetAnotherConfigLib-98f29ec5c30d23999fce37d7daf7aba8f10f25d3.tar.bz2 YetAnotherConfigLib-98f29ec5c30d23999fce37d7daf7aba8f10f25d3.zip |
Add @OverrideName and @OverrideFormat
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/impl')
11 files changed, 54 insertions, 40 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java index 208f78e..063a177 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.BooleanControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.BooleanController; import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; @@ -11,7 +12,7 @@ import java.util.function.Function; public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl<Boolean> implements BooleanControllerBuilder { private boolean coloured = false; - private Function<Boolean, Component> formatter = BooleanController.ON_OFF_FORMATTER; + private ValueFormatter<Boolean> formatter = BooleanController.ON_OFF_FORMATTER::apply; public BooleanControllerBuilderImpl(Option<Boolean> option) { super(option); @@ -24,8 +25,8 @@ public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl< } @Override - public BooleanControllerBuilder valueFormatter(Function<Boolean, Component> formatter) { - Validate.notNull(formatter); + public BooleanControllerBuilder formatValue(ValueFormatter<Boolean> formatter) { + Validate.notNull(formatter, "formatter cannot be null"); this.formatter = formatter; return this; @@ -33,24 +34,24 @@ public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl< @Override public BooleanControllerBuilder onOffFormatter() { - this.formatter = BooleanController.ON_OFF_FORMATTER; + this.formatter = BooleanController.ON_OFF_FORMATTER::apply; return this; } @Override public BooleanControllerBuilder yesNoFormatter() { - this.formatter = BooleanController.YES_NO_FORMATTER; + this.formatter = BooleanController.YES_NO_FORMATTER::apply; return this; } @Override public BooleanControllerBuilder trueFalseFormatter() { - this.formatter = BooleanController.TRUE_FALSE_FORMATTER; + this.formatter = BooleanController.TRUE_FALSE_FORMATTER::apply; return this; } @Override public Controller<Boolean> build() { - return new BooleanController(option, formatter, coloured); + return BooleanController.createInternal(option, formatter, coloured); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java index 63045f2..8e2e481 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java @@ -4,14 +4,12 @@ import com.google.common.collect.ImmutableList; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.CyclingListControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.cycling.CyclingListController; -import net.minecraft.network.chat.Component; - -import java.util.function.Function; public final class CyclingListControllerBuilderImpl<T> extends AbstractControllerBuilderImpl<T> implements CyclingListControllerBuilder<T> { private Iterable<? extends T> values; - private Function<T, Component> formatter = null; + private ValueFormatter<T> formatter = null; public CyclingListControllerBuilderImpl(Option<T> option) { super(option); @@ -31,13 +29,13 @@ public final class CyclingListControllerBuilderImpl<T> extends AbstractControlle } @Override - public CyclingListControllerBuilder<T> valueFormatter(Function<T, Component> formatter) { + public CyclingListControllerBuilder<T> formatValue(ValueFormatter<T> formatter) { this.formatter = formatter; return this; } @Override public Controller<T> build() { - return new CyclingListController<>(option, values, formatter); + return CyclingListController.createInternal(option, values, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java index 56e1d44..8d84e7d 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.DoubleFieldControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController; import dev.isxander.yacl3.gui.controllers.string.number.DoubleFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class DoubleFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Double> implements DoubleFieldControllerBuilder { private double min = Double.MIN_VALUE; private double max = Double.MAX_VALUE; - private Function<Double, Component> formatter = DoubleSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Double> formatter = DoubleSliderController.DEFAULT_FORMATTER::apply; public DoubleFieldControllerBuilderImpl(Option<Double> option) { super(option); @@ -38,13 +39,13 @@ public class DoubleFieldControllerBuilderImpl extends AbstractControllerBuilderI } @Override - public DoubleFieldControllerBuilder valueFormatter(Function<Double, Component> formatter) { + public DoubleFieldControllerBuilder formatValue(ValueFormatter<Double> formatter) { this.formatter = formatter; return this; } @Override public Controller<Double> build() { - return new DoubleFieldController(option, min, max, formatter); + return DoubleFieldController.createInternal(option, min, max, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java index a636abf..b696d57 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.DoubleSliderControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class DoubleSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Double> implements DoubleSliderControllerBuilder { private double min, max; private double step; - private Function<Double, Component> formatter = DoubleSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Double> formatter = DoubleSliderController.DEFAULT_FORMATTER::apply; public DoubleSliderControllerBuilderImpl(Option<Double> option) { super(option); @@ -31,13 +32,13 @@ public class DoubleSliderControllerBuilderImpl extends AbstractControllerBuilder } @Override - public DoubleSliderControllerBuilder valueFormatter(Function<Double, Component> formatter) { + public DoubleSliderControllerBuilder formatValue(ValueFormatter<Double> formatter) { this.formatter = formatter; return this; } @Override public Controller<Double> build() { - return new DoubleSliderController(option, min, max, step, formatter); + return DoubleSliderController.createInternal(option, min, max, step, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java index 3237dbf..04ee2a0 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.EnumControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.cycling.EnumController; import net.minecraft.network.chat.Component; @@ -10,7 +11,7 @@ import java.util.function.Function; public class EnumControllerBuilderImpl<T extends Enum<T>> extends AbstractControllerBuilderImpl<T> implements EnumControllerBuilder<T> { private Class<T> enumClass; - private Function<T, Component> formatter = EnumController.getDefaultFormatter(); + private ValueFormatter<T> formatter = null; public EnumControllerBuilderImpl(Option<T> option) { super(option); @@ -23,13 +24,19 @@ public class EnumControllerBuilderImpl<T extends Enum<T>> extends AbstractContro } @Override - public EnumControllerBuilder<T> valueFormatter(Function<T, Component> formatter) { + public EnumControllerBuilder<T> formatValue(ValueFormatter<T> formatter) { this.formatter = formatter; return this; } @Override public Controller<T> build() { - return new EnumController<>(option, formatter, enumClass.getEnumConstants()); + ValueFormatter<T> formatter = this.formatter; + if (formatter == null) { + Function<T, Component> formatFunction = EnumController.getDefaultFormatter(); + formatter = formatFunction::apply; + } + + return EnumController.createInternal(option, formatter, enumClass.getEnumConstants()); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java index 09dbce0..08fefd0 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController; import dev.isxander.yacl3.gui.controllers.string.number.FloatFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class FloatFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Float> implements FloatFieldControllerBuilder { private float min = Float.MIN_VALUE; private float max = Float.MAX_VALUE; - private Function<Float, Component> formatter = FloatSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Float> formatter = FloatSliderController.DEFAULT_FORMATTER::apply; public FloatFieldControllerBuilderImpl(Option<Float> option) { super(option); @@ -38,13 +39,13 @@ public class FloatFieldControllerBuilderImpl extends AbstractControllerBuilderIm } @Override - public FloatFieldControllerBuilder valueFormatter(Function<Float, Component> formatter) { + public FloatFieldControllerBuilder formatValue(ValueFormatter<Float> formatter) { this.formatter = formatter; return this; } @Override public Controller<Float> build() { - return new FloatFieldController(option, min, max, formatter); + return FloatFieldController.createInternal(option, min, max, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java index c9699fb..9b2d75b 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class FloatSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Float> implements FloatSliderControllerBuilder { private float min, max; private float step; - private Function<Float, Component> formatter = FloatSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Float> formatter = FloatSliderController.DEFAULT_FORMATTER::apply; public FloatSliderControllerBuilderImpl(Option<Float> option) { super(option); @@ -31,13 +32,13 @@ public class FloatSliderControllerBuilderImpl extends AbstractControllerBuilderI } @Override - public FloatSliderControllerBuilder valueFormatter(Function<Float, Component> formatter) { + public FloatSliderControllerBuilder formatValue(ValueFormatter<Float> formatter) { this.formatter = formatter; return this; } @Override public Controller<Float> build() { - return new FloatSliderController(option, min, max, step, formatter); + return FloatSliderController.createInternal(option, min, max, step, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java index 73b51a0..1435c49 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController; import dev.isxander.yacl3.gui.controllers.string.number.IntegerFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class IntegerFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Integer> implements IntegerFieldControllerBuilder { private int min = Integer.MIN_VALUE; private int max = Integer.MAX_VALUE; - private Function<Integer, Component> formatter = IntegerSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Integer> formatter = IntegerSliderController.DEFAULT_FORMATTER::apply; public IntegerFieldControllerBuilderImpl(Option<Integer> option) { super(option); @@ -38,13 +39,13 @@ public class IntegerFieldControllerBuilderImpl extends AbstractControllerBuilder } @Override - public IntegerFieldControllerBuilder valueFormatter(Function<Integer, Component> formatter) { + public IntegerFieldControllerBuilder formatValue(ValueFormatter<Integer> formatter) { this.formatter = formatter; return this; } @Override public Controller<Integer> build() { - return new IntegerFieldController(option, min, max, formatter); + return IntegerFieldController.createInternal(option, min, max, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java index 106c22a..b9395a0 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class IntegerSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Integer> implements IntegerSliderControllerBuilder { private int min, max; private int step; - private Function<Integer, Component> formatter = IntegerSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Integer> formatter = IntegerSliderController.DEFAULT_FORMATTER::apply; public IntegerSliderControllerBuilderImpl(Option<Integer> option) { super(option); @@ -31,13 +32,13 @@ public class IntegerSliderControllerBuilderImpl extends AbstractControllerBuilde } @Override - public IntegerSliderControllerBuilder valueFormatter(Function<Integer, Component> formatter) { + public IntegerSliderControllerBuilder formatValue(ValueFormatter<Integer> formatter) { this.formatter = formatter; return this; } @Override public Controller<Integer> build() { - return new IntegerSliderController(option, min, max, step, formatter); + return IntegerSliderController.createInternal(option, min, max, step, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java index 88cb610..c7a3ea4 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.LongFieldControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.LongSliderController; import dev.isxander.yacl3.gui.controllers.string.number.LongFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class LongFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Long> implements LongFieldControllerBuilder { private long min = Long.MIN_VALUE; private long max = Long.MAX_VALUE; - private Function<Long, Component> formatter = LongSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Long> formatter = LongSliderController.DEFAULT_FORMATTER::apply; public LongFieldControllerBuilderImpl(Option<Long> option) { super(option); @@ -38,13 +39,13 @@ public class LongFieldControllerBuilderImpl extends AbstractControllerBuilderImp } @Override - public LongFieldControllerBuilder valueFormatter(Function<Long, Component> formatter) { + public LongFieldControllerBuilder formatValue(ValueFormatter<Long> formatter) { this.formatter = formatter; return this; } @Override public Controller<Long> build() { - return new LongFieldController(option, min, max, formatter); + return LongFieldController.createInternal(option, min, max, formatter); } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java index 2bd932a..5eda424 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl3.impl.controller; import dev.isxander.yacl3.api.Controller; import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.controller.LongSliderControllerBuilder; +import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.LongSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class LongSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Long> implements LongSliderControllerBuilder { private long min, max; private long step; - private Function<Long, Component> formatter = LongSliderController.DEFAULT_FORMATTER; + private ValueFormatter<Long> formatter = LongSliderController.DEFAULT_FORMATTER::apply; public LongSliderControllerBuilderImpl(Option<Long> option) { super(option); @@ -31,13 +32,13 @@ public class LongSliderControllerBuilderImpl extends AbstractControllerBuilderIm } @Override - public LongSliderControllerBuilder valueFormatter(Function<Long, Component> formatter) { + public LongSliderControllerBuilder formatValue(ValueFormatter<Long> formatter) { this.formatter = formatter; return this; } @Override public Controller<Long> build() { - return new LongSliderController(option, min, max, step, formatter); + return LongSliderController.createInternal(option, min, max, step, formatter); } } |