Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v1' into v1
Browse files Browse the repository at this point in the history
# Conflicts:
#	modules/root.gradle.kts
#	versions/preprocessor.gradle.kts
  • Loading branch information
pauliesnug committed Jun 2, 2024
2 parents f714d4b + cafb64d commit ee1dcc3
Show file tree
Hide file tree
Showing 113 changed files with 1,919 additions and 2,472 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name=OneConfig
mod_id=oneconfig
version_major=1
version_minor=0
version_patch=0-alpha4
version_patch=0-alpha5

polyfrost.defaults.loom=2

Expand Down
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.9.23"
kotlinx-coroutines = "1.8.0"
kotlinx-coroutines = "1.8.1"
kotlinx-atomicfu = "0.24.0"
kotlinx-abi = "0.14.0"

Expand All @@ -18,6 +18,7 @@ nightconfig = "3.6.6"
lwjgl = "3.3.3"
universalcraft = "296"
mixin = "0.7.11-SNAPSHOT"
hypixel-modapi = "0.4.0"

junit-bom = "5.10.2"

Expand All @@ -27,6 +28,8 @@ junit-bom = { module = "org.junit:junit-bom", version.ref = "junit-bom" }

mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }

hypixel-modapi = { module = "net.hypixel:mod-api", version.ref = "hypixel-modapi" }

polyui = { module = "org.polyfrost:polyui", version.ref = "polyui" }

annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
14 changes: 7 additions & 7 deletions modules/commands/api/commands.api
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class org/polyfrost/oneconfig/api/commands/v1/CommandTree : org/polyfrost
public fun getDedupedCommands ()Ljava/util/Map;
public fun getHelp ()[Ljava/lang/String;
public fun getTree ([Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree;
public fun getWithArgs ([Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/commands/v1/util/Pair;
public fun getWithArgs ([Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree$Result;
public fun init ()V
public fun isInitialized ()Z
public fun onExecs (Ljava/util/function/Consumer;[Ljava/lang/String;)V
Expand All @@ -31,13 +31,19 @@ public class org/polyfrost/oneconfig/api/commands/v1/CommandTree : org/polyfrost
public fun toString ()Ljava/lang/String;
}

public final class org/polyfrost/oneconfig/api/commands/v1/CommandTree$Result {
public final field args [Ljava/lang/String;
public final field nodes Ljava/util/List;
}

public class org/polyfrost/oneconfig/api/commands/v1/Executable : org/polyfrost/oneconfig/api/commands/v1/Node {
public final field arity I
public final field function Ljava/util/function/Function;
public final field isGreedy Z
public final field parameters [Lorg/polyfrost/oneconfig/api/commands/v1/Executable$Param;
public fun <init> ([Ljava/lang/String;Ljava/lang/String;[Lorg/polyfrost/oneconfig/api/commands/v1/Executable$Param;ZLjava/util/function/Function;)V
public fun equals (Ljava/lang/Object;)Z
public fun execute ()Ljava/lang/Object;
public fun execute ([Ljava/lang/String;)Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down Expand Up @@ -266,9 +272,3 @@ public final class org/polyfrost/oneconfig/api/commands/v1/factories/dsl/DSLFact
public fun create (Ljava/util/Map;Ljava/lang/Object;)Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree;
}

public class org/polyfrost/oneconfig/api/commands/v1/util/Pair {
public field first Ljava/lang/Object;
public field second Ljava/lang/Object;
public fun <init> (Ljava/lang/Object;Ljava/lang/Object;)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.polyfrost.oneconfig.api.commands.v1.arguments.ArgumentParser;
import org.polyfrost.oneconfig.api.commands.v1.exceptions.CommandCreationException;
import org.polyfrost.oneconfig.api.commands.v1.exceptions.CommandExecutionException;
import org.polyfrost.oneconfig.api.commands.v1.util.Pair;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -42,7 +41,6 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* Internal representation of a command in OneConfig.
Expand Down Expand Up @@ -238,7 +236,7 @@ public List<Node> get(String path) {
*
* @see #get(String...)
*/
public Pair<@Nullable List<Node>, @NotNull String[]> getWithArgs(String... path) {
public Result getWithArgs(String... path) {
CommandTree self = this;
List<Node> ls = null;
int i = 1;
Expand Down Expand Up @@ -276,7 +274,7 @@ public List<Node> get(String path) {
}
String[] rest = new String[Math.max(0, path.length - i)];
if (rest.length != 0) System.arraycopy(path, i, rest, 0, rest.length);
return new Pair<>(ls, rest);
return new Result(ls, rest);
}

/**
Expand All @@ -303,19 +301,15 @@ public void onExecs(Consumer<Executable> func, String... path) {
*/
public Object execute(String... usage) {
if (usage.length == 0) usage = new String[]{""};
Pair<List<Node>, String[]> pair = getWithArgs(usage);
if (pair.first == null) throw new CommandExecutionException("Command not found!");
String[] args = pair.second;
List<Node> ls = pair.first.stream().filter(node -> node instanceof Executable && (((Executable) node).isGreedy || ((Executable) node).arity == args.length))
.collect(Collectors.toList());
if (ls.isEmpty()) throw new CommandExecutionException("Command not found!");
if (ls.size() == 1) {
Executable exe = (Executable) ls.get(0);
return exe.execute(args);
}
Result res = getWithArgs(usage);
if (res.nodes == null || res.nodes.isEmpty()) throw new CommandExecutionException("Command not found!");
List<Node> nodes = res.nodes;
String[] args = res.args;
loop:
for (Node node : ls) {
for (Node node : nodes) {
if (!(node instanceof Executable)) continue;
Executable exe = (Executable) node;
if (!exe.isGreedy && args.length != exe.arity) continue;
if (exe.arity == 0 && args.length == 0) {
return exe.execute();
}
Expand Down Expand Up @@ -352,16 +346,16 @@ public List<String> autocomplete(String... current) {
if (current.length == 0) return null;
Node n;
String thisArg = current[current.length - 1];
Pair<List<Node>, String[]> res = getWithArgs(current);
if (res == null) {
Result res = getWithArgs(current);
if (res.nodes == null) {
String[] last = new String[current.length - 1];
System.arraycopy(current, 0, last, 0, last.length);
// move back, check if we have something valid available on the last
// like /hello gj where gj is not valid, check /hello for if it can match any
n = getTree(last);
if (n == null) return null;
} else {
n = res.first.get(0);
n = res.nodes.get(0);
}
if (n instanceof CommandTree) {
CommandTree c = (CommandTree) n;
Expand All @@ -374,11 +368,11 @@ public List<String> autocomplete(String... current) {
}
return ls.isEmpty() ? null : ls;
} else {
if (res.second.length == 0) thisArg = "";
if (res.args.length == 0) thisArg = "";
Executable e = (Executable) n;
// fast path: we already past the end of this command, don't try
if (res.second.length > e.parameters.length || e.parameters.length == 0) return null;
Executable.Param param = e.parameters[Math.max(0, res.second.length - 1)];
if (res.args.length > e.parameters.length || e.parameters.length == 0) return null;
Executable.Param param = e.parameters[Math.max(0, res.args.length - 1)];
List<String> l = param.tryAutoComplete(thisArg);
if (l == null || l.isEmpty()) return null;
if (l.contains(thisArg)) {
Expand All @@ -387,4 +381,19 @@ public List<String> autocomplete(String... current) {
} else return l;
}
}

/**
* Represents a result from a {@link #getWithArgs(String...)} call. This class is a wrapper around a set of possible candidates for the given path, and their arguments.
*/
public static final class Result {
@Nullable
public final List<@NotNull Node> nodes;
@NotNull
public final String[] args;

Result(@Nullable List<@NotNull Node> nodes, @NotNull String[] args) {
this.nodes = nodes;
this.args = args;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public Executable(@NotNull String[] names, @Nullable String description, @NotNul
this.arity = arity;
}

public Object execute() {
if(arity != 0) throw new CommandExecutionException("Invalid number of arguments!");
return function.apply(null);
}

public Object execute(String... args) {
if (!isGreedy && args.length != arity) throw new CommandExecutionException("Invalid number of arguments!");
Object[] parsed = new Object[parameters.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CommandDSL @JvmOverloads constructor(private val parsers: Map<Class<*>, Ar
description,
mapParams(method, paramData, parsers),
greedy
) { m.invokeWithArguments(*it) }
) { if (it == null) m.invoke() else m.invokeWithArguments(*it) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun interface Visualizer {
size = Vec2(300f, 32f),
text = text ?: "oneconfig.button.default",
).events {
Event.Mouse.Clicked then {
Event.Mouse.Companion.Clicked then {
action.run()
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ fun interface Visualizer {
visibleSize = Vec2(300f, 32f),
text = prop.getAs<Number>().toString(),
).events {
Event.Change.Text then {
Event.Change.Companion.Text then {
if (it.text.isEmpty()) return@then
try {
val v = it.text.toFloat()
Expand Down Expand Up @@ -140,7 +140,7 @@ fun interface Visualizer {
initial = prop.type.enumConstants.indexOf(prop.get()),
optionLateralPadding = 20f,
).events {
Event.Change.Number then {
Event.Change.Companion.Number then {
prop.setAs(it.amount)
}
}
Expand All @@ -156,7 +156,7 @@ fun interface Visualizer {
initial = prop.getAs(),
optionLateralPadding = 20f,
).events {
Event.Change.Number then {
Event.Change.Companion.Number then {
prop.setAs(it.amount)
}
}
Expand All @@ -175,7 +175,7 @@ fun interface Visualizer {
max = max,
initialValue = prop.getAs<Number>().toFloat(),
).events {
Event.Change.Number then {
Event.Change.Companion.Number then {
prop.setAs(it.amount)
}
}
Expand All @@ -191,7 +191,7 @@ fun interface Visualizer {
size = 21f,
state = state,
).events {
Event.Change.State then {
Event.Change.Companion.State then {
prop.setAs(it.state)
}
}
Expand All @@ -207,7 +207,7 @@ fun interface Visualizer {
visibleSize = Vec2(200f, 12f),
text = prop.getAs(),
).events {
Event.Change.Text then {
Event.Change.Companion.Text then {
prop.setAs(it.text)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ open class ConfigVisualizer {
return Group(
children = categories.mapToArray { (category, options) ->
Button(text = category).events {
Event.Mouse.Clicked then {
Event.Mouse.Companion.Clicked then {
parent[0] = options
}
}
Expand All @@ -179,7 +179,7 @@ open class ConfigVisualizer {
wrap(Image("chevron-down.svg".image()).also { it.rotation = PI }, title, desc, icon).events {
self.color = PolyColor.TRANSPARENT.toAnimatable()
var open = false
Event.Mouse.Clicked then {
Event.Mouse.Companion.Clicked then {
open = !open
Rotate(this[1], if (!open) PI else 0.0, false, Animations.EaseOutQuad.create(0.2.seconds)).add()
val value = parent[1].height
Expand Down
Loading

0 comments on commit ee1dcc3

Please sign in to comment.