diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/Action.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/Action.java index 02fbd35c..d2a6a47e 100644 --- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/Action.java +++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/Action.java @@ -21,6 +21,7 @@ import com.xpdustry.distributor.api.DistributorProvider; import com.xpdustry.distributor.api.audience.Audience; import com.xpdustry.distributor.api.key.Key; +import java.util.List; import java.util.function.Consumer; import java.util.function.Function; import mindustry.Vars; @@ -178,6 +179,40 @@ static Action show(final WindowManager manager) { return window -> manager.create(window).show(); } + /** + * Returns an action using the result of the given delegate to run another action. + * + * @param delegate the delegate + * @return the action + */ + static Action delegate(final Function delegate) { + return window -> delegate.apply(window).act(window); + } + + /** + * Returns an action composed of multiple actions. + * + * @param actions the actions + * @return the action + */ + static Action compose(final Action... actions) { + return compose(List.of(actions)); + } + + /** + * Returns an action composed of multiple actions. + * + * @param actions the actions + * @return the action + */ + static Action compose(final List actions) { + return window -> { + for (final var action : actions) { + action.act(window); + } + }; + } + /** * Executes the action. * diff --git a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/BiAction.java b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/BiAction.java index 565ef2aa..4c86e280 100644 --- a/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/BiAction.java +++ b/distributor-common-api/src/main/java/com/xpdustry/distributor/api/gui/BiAction.java @@ -19,6 +19,8 @@ package com.xpdustry.distributor.api.gui; import com.xpdustry.distributor.api.key.Key; +import java.util.List; +import java.util.function.BiFunction; /** * A function that is executed when an interaction occurs in a gui. Takes an additional parameter as the input. @@ -47,6 +49,41 @@ static BiAction with(final Key key) { return (window, value) -> window.getState().set(key, value); } + /** + * Returns a bi-action using the result of the given delegate to run another action. + * + * @param delegate the delegate + * @return the bi-action + */ + static BiAction delegate(final BiFunction delegate) { + return (window, value) -> delegate.apply(window, value).act(window); + } + + /** + * Returns a bi-action composed of multiple bi-actions. + * + * @param actions the bi-actions + * @return the bi-action + */ + @SafeVarargs + static BiAction compose(final BiAction... actions) { + return compose(List.of(actions)); + } + + /** + * Returns a bi-action composed of multiple bi-actions. + * + * @param actions the bi-actions + * @return the bi-action + */ + static BiAction compose(final List> actions) { + return (window, value) -> { + for (final var action : actions) { + action.act(window, value); + } + }; + } + /** * Executes the bi-action. *