diff options
author | Xander <xander@isxander.dev> | 2023-04-25 16:28:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-25 16:28:41 +0100 |
commit | 13c7ba45ff201423eb8dba8a40cfb66ebb531439 (patch) | |
tree | 1e799aa9da11fbc0833bc6b7c6e6799633c2ec50 /src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java | |
parent | 8ba7196ae990fe9aa98680aba1b387e385fff99c (diff) | |
download | YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.tar.gz YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.tar.bz2 YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.zip |
Architectury! (#61)
Diffstat (limited to 'src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java')
-rw-r--r-- | src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java deleted file mode 100644 index 68f53a0..0000000 --- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -package dev.isxander.yacl.impl; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.api.ListOption; -import dev.isxander.yacl.api.Option; -import dev.isxander.yacl.api.OptionGroup; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.ComponentContents; -import net.minecraft.network.chat.MutableComponent; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -@ApiStatus.Internal -public final class OptionGroupImpl implements OptionGroup { - private final @NotNull Component name; - private final @NotNull Component tooltip; - private final ImmutableList<? extends Option<?>> options; - private final boolean collapsed; - private final boolean isRoot; - - public OptionGroupImpl(@NotNull Component name, @NotNull Component tooltip, ImmutableList<? extends Option<?>> options, boolean collapsed, boolean isRoot) { - this.name = name; - this.tooltip = tooltip; - this.options = options; - this.collapsed = collapsed; - this.isRoot = isRoot; - } - - @Override - public @NotNull Component name() { - return name; - } - - @Override - public @NotNull Component tooltip() { - return tooltip; - } - - @Override - public @NotNull ImmutableList<? extends Option<?>> options() { - return options; - } - - @Override - public boolean collapsed() { - return collapsed; - } - - @Override - public boolean isRoot() { - return isRoot; - } - - @ApiStatus.Internal - public static final class BuilderImpl implements OptionGroup.Builder { - private Component name = Component.empty(); - private final List<Component> tooltipLines = new ArrayList<>(); - private final List<Option<?>> options = new ArrayList<>(); - private boolean collapsed = false; - - @Override - public Builder name(@NotNull Component name) { - Validate.notNull(name, "`name` must not be null"); - - this.name = name; - return this; - } - - @Override - public Builder tooltip(@NotNull Component... tooltips) { - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); - - tooltipLines.addAll(List.of(tooltips)); - return this; - } - - @Override - public Builder option(@NotNull Option<?> option) { - Validate.notNull(option, "`option` must not be null"); - - if (option instanceof ListOption<?>) - throw new UnsupportedOperationException("List options must not be added as an option but a group!"); - - this.options.add(option); - return this; - } - - @Override - public Builder options(@NotNull Collection<? extends Option<?>> options) { - Validate.notEmpty(options, "`options` must not be empty"); - - if (options.stream().anyMatch(ListOption.class::isInstance)) - throw new UnsupportedOperationException("List options must not be added as an option but a group!"); - - this.options.addAll(options); - return this; - } - - @Override - public Builder collapsed(boolean collapsible) { - this.collapsed = collapsible; - return this; - } - - @Override - public OptionGroup build() { - Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`"); - - MutableComponent concatenatedTooltip = Component.empty(); - boolean first = true; - for (Component line : tooltipLines) { - if (line.getContents() == ComponentContents.EMPTY) - continue; - - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line); - } - - return new OptionGroupImpl(name, concatenatedTooltip, ImmutableList.copyOf(options), collapsed, false); - } - } -} |