-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/v9' into v10
# Conflicts: # common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java # common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java # gradle.properties
- Loading branch information
Showing
42 changed files
with
700 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
common/src/main/java/me/shedaniel/clothconfig2/api/DisableableWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of Cloth Config. | ||
* Copyright (C) 2020 - 2021 shedaniel | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package me.shedaniel.clothconfig2.api; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Experimental | ||
public interface DisableableWidget { | ||
|
||
/** | ||
* Checks whether this config entry gui is enabled. | ||
* | ||
* <p>Requirements are checked independently (once per tick). This method simply reads the result of the latest | ||
* check, making it extremely cheap to run. | ||
* | ||
* <p>If {@link HideableWidget#isDisplayed()} is false, this will also be false. | ||
* | ||
* @return whether the config entry is enabled | ||
* @see HideableWidget#isDisplayed() | ||
* @see TickableWidget#tick() | ||
*/ | ||
boolean isEnabled(); | ||
|
||
void setRequirement(@Nullable Requirement requirement); | ||
|
||
@Nullable Requirement getRequirement(); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
common/src/main/java/me/shedaniel/clothconfig2/api/HideableWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of Cloth Config. | ||
* Copyright (C) 2020 - 2021 shedaniel | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package me.shedaniel.clothconfig2.api; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Experimental | ||
public interface HideableWidget { | ||
|
||
/** | ||
* Checks whether this config entry gui is shown on screen. | ||
* | ||
* <p>Requirements are checked independently (once per tick). This method simply reads the result of the latest | ||
* check, making it extremely cheap to run. | ||
* | ||
* @return whether to display the config entry | ||
* @see DisableableWidget#isEnabled() | ||
* @see TickableWidget#tick() | ||
*/ | ||
boolean isDisplayed(); | ||
|
||
void setDisplayRequirement(@Nullable Requirement requirement); | ||
|
||
@Nullable Requirement getDisplayRequirement(); | ||
} |
124 changes: 124 additions & 0 deletions
124
common/src/main/java/me/shedaniel/clothconfig2/api/Requirement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* This file is part of Cloth Config. | ||
* Copyright (C) 2020 - 2021 shedaniel | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package me.shedaniel.clothconfig2.api; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Represents a predicate (boolean-valued function) without arguments. | ||
* | ||
* <p>This is a <a href="{@docRoot}/java/util/function/package-summary.html">functional interface</a> | ||
* whose functional method is {@link #check()}. | ||
*/ | ||
@FunctionalInterface | ||
@ApiStatus.Experimental | ||
public interface Requirement { | ||
|
||
/** | ||
* Checks if this requirement is currently true. | ||
*/ | ||
boolean check(); | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when {@code dependency}'s value is one of the provided values. | ||
*/ | ||
@SafeVarargs | ||
static <T> Requirement isValue(ValueHolder<T> dependency, @Nullable T firstValue, @Nullable T... otherValues) { | ||
Set<@Nullable T> values = Stream.concat(Stream.of(firstValue), Arrays.stream(otherValues)) | ||
.collect(Collectors.toCollection(HashSet::new)); | ||
|
||
return () -> values.contains(dependency.getValue()); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when {@code firstDependency}'s value equals {@code secondDependency}'s value. | ||
*/ | ||
static <T> Requirement matches(ValueHolder<T> firstDependency, ValueHolder<T> secondDependency) { | ||
return () -> Objects.equals(firstDependency.getValue(), secondDependency.getValue()); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when {@code dependency}'s value is true. | ||
*/ | ||
static Requirement isTrue(ValueHolder<Boolean> dependency) { | ||
return () -> Boolean.TRUE.equals(dependency.getValue()); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when {@code dependency}'s value is false. | ||
*/ | ||
static Requirement isFalse(ValueHolder<Boolean> dependency) { | ||
return () -> Boolean.FALSE.equals(dependency.getValue()); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when the given {@code requirement} is false. | ||
*/ | ||
static Requirement not(Requirement requirement) { | ||
return () -> !requirement.check(); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when all the given requirements are true. | ||
*/ | ||
static Requirement all(Requirement... requirements) { | ||
return () -> Arrays.stream(requirements).allMatch(Requirement::check); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when any of the given requirements are true. | ||
*/ | ||
static Requirement any(Requirement... requirements) { | ||
return () -> Arrays.stream(requirements).anyMatch(Requirement::check); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when none of the given requirements are true, i.e. all are false. | ||
*/ | ||
static Requirement none(Requirement... requirements) { | ||
return () -> Arrays.stream(requirements).noneMatch(Requirement::check); | ||
} | ||
|
||
/** | ||
* Generates a {@link Requirement} that is true when precisely one of the given requirements is true. | ||
*/ | ||
static Requirement one(Requirement... requirements) { | ||
return () -> { | ||
// Use a for loop instead of Stream.count() so that we can return early. We only need to count past 1. | ||
boolean oneFound = false; | ||
for (Requirement requirement : requirements) { | ||
if (!requirement.check()) | ||
continue; | ||
if (oneFound) | ||
return false; | ||
oneFound = true; | ||
} | ||
return oneFound; | ||
}; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
common/src/main/java/me/shedaniel/clothconfig2/api/ValueHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This file is part of Cloth Config. | ||
* Copyright (C) 2020 - 2021 shedaniel | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package me.shedaniel.clothconfig2.api; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface ValueHolder<T> { | ||
/** | ||
* Get the value held by this Value Holder. | ||
* | ||
* <p>Depending on the implementation, this method may or may not be {@link Nullable}. | ||
* | ||
* @return the current value. | ||
*/ | ||
T getValue(); | ||
} |
Oops, something went wrong.