1
0
forked from Clones/Controlify

refactor binding api (sorry enjarai)

This commit is contained in:
isXander
2023-04-14 20:11:57 +01:00
parent 07b57d5637
commit abe6b27cef
16 changed files with 183 additions and 109 deletions

View File

@ -0,0 +1,10 @@
package dev.isxander.controlify.api.bind;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.isxander.controlify.gui.DrawSize;
public interface BindRenderer {
DrawSize size();
void render(PoseStack poseStack, int x, int centerY);
}

View File

@ -0,0 +1,8 @@
package dev.isxander.controlify.api.bind;
import dev.isxander.controlify.controller.Controller;
@FunctionalInterface
public interface BindingSupplier {
ControllerBinding onController(Controller<?, ?> controller);
}

View File

@ -1,7 +1,6 @@
package dev.isxander.controlify.api.bind;
import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.bindings.BindingSupplier;
import dev.isxander.controlify.bindings.ControllerBindings;
import dev.isxander.controlify.bindings.GamepadBinds;
import net.minecraft.client.KeyMapping;

View File

@ -0,0 +1,37 @@
package dev.isxander.controlify.api.bind;
import com.google.gson.JsonObject;
import net.minecraft.client.KeyMapping;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import java.util.function.BooleanSupplier;
public interface ControllerBinding {
float state();
float prevState();
boolean held();
boolean prevHeld();
boolean justPressed();
boolean justReleased();
Component name();
Component description();
Component category();
ResourceLocation id();
KeyMappingOverride override();
void resetBind();
boolean isUnbound();
BindRenderer renderer();
JsonObject toJson();
record KeyMappingOverride(KeyMapping keyMapping, BooleanSupplier toggleable) {
}
}

View File

@ -1,6 +1,6 @@
package dev.isxander.controlify.api.bind;
import dev.isxander.controlify.bindings.ControllerBinding;
import dev.isxander.controlify.bindings.ControllerBindingImpl;
import dev.isxander.controlify.bindings.GamepadBinds;
import dev.isxander.controlify.bindings.IBind;
import dev.isxander.controlify.controller.Controller;
@ -13,7 +13,7 @@ import java.util.function.BooleanSupplier;
public interface ControllerBindingBuilder<T extends ControllerState> {
static <T extends ControllerState> ControllerBindingBuilder<T> create(Controller<T, ?> controller) {
return new ControllerBinding.ControllerBindingBuilderImpl<>(controller);
return new ControllerBindingImpl.ControllerBindingBuilderImpl<>(controller);
}
/**
@ -92,5 +92,5 @@ public interface ControllerBindingBuilder<T extends ControllerState> {
*/
ControllerBindingBuilder<T> vanillaOverride(KeyMapping keyMapping);
ControllerBinding<T> build();
ControllerBinding build();
}

View File

@ -1,6 +1,6 @@
package dev.isxander.controlify.api.buttonguide;
import dev.isxander.controlify.bindings.ControllerBinding;
import dev.isxander.controlify.api.bind.ControllerBinding;
import dev.isxander.controlify.bindings.ControllerBindings;
import dev.isxander.controlify.gui.ButtonGuideRenderer;
import net.minecraft.client.gui.components.AbstractButton;
@ -25,7 +25,7 @@ public final class ButtonGuideApi {
*/
public static <T extends AbstractButton> void addGuideToButton(
T button,
Function<ControllerBindings<?>, ControllerBinding<?>> binding,
Function<ControllerBindings<?>, ControllerBinding> binding,
ButtonRenderPosition position,
ButtonGuidePredicate<T> renderPredicate) {
ButtonGuideRenderer.registerBindingForButton(button, binding, position, renderPredicate);

View File

@ -1,6 +1,6 @@
package dev.isxander.controlify.api.ingameguide;
import dev.isxander.controlify.bindings.ControllerBinding;
import dev.isxander.controlify.api.bind.ControllerBinding;
/**
* Allows you to register your own actions to the button guide.
@ -16,7 +16,7 @@ public interface IngameGuideRegistry {
* @param priority the priority of the action, used to sort the list.
* @param supplier the supplier for the name of the action. can be empty to hide the action.
*/
void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, ActionPriority priority, GuideActionNameSupplier supplier);
void registerGuideAction(ControllerBinding binding, ActionLocation location, ActionPriority priority, GuideActionNameSupplier supplier);
/**
* Registers a new action to the button guide.
@ -25,5 +25,5 @@ public interface IngameGuideRegistry {
* @param location the location of the action, left or right.
* @param supplier the supplier for the name of the action. can be empty to hide the action.
*/
void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, GuideActionNameSupplier supplier);
void registerGuideAction(ControllerBinding binding, ActionLocation location, GuideActionNameSupplier supplier);
}