forked from Clones/Controlify
compound binds, complete vanilla compat, better vmouse screen handling, controller uuid, beta notice screen, configurable movement keys, vmouse shift key, icon, optimize controller save/load
This commit is contained in:
38
src/main/java/dev/isxander/controlify/bindings/IBind.java
Normal file
38
src/main/java/dev/isxander/controlify/bindings/IBind.java
Normal file
@ -0,0 +1,38 @@
|
||||
package dev.isxander.controlify.bindings;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.controller.ControllerState;
|
||||
import dev.isxander.controlify.gui.ButtonRenderer;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface IBind {
|
||||
float state(ControllerState state, Controller controller);
|
||||
default boolean held(ControllerState state, Controller controller) {
|
||||
return state(state, controller) > controller.config().buttonActivationThreshold;
|
||||
}
|
||||
|
||||
void draw(PoseStack matrices, int x, int centerY, Controller controller);
|
||||
ButtonRenderer.DrawSize drawSize();
|
||||
|
||||
JsonElement toJson();
|
||||
|
||||
static IBind fromJson(JsonElement json) {
|
||||
if (json.isJsonArray()) {
|
||||
return new CompoundBind(json.getAsJsonArray().asList().stream().map(element -> Bind.fromIdentifier(element.getAsString())).toArray(Bind[]::new));
|
||||
} else {
|
||||
return Bind.fromIdentifier(json.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
static IBind create(Collection<Bind> binds) {
|
||||
if (binds.size() == 1) return binds.stream().findAny().orElseThrow();
|
||||
return new CompoundBind(binds.toArray(new Bind[0]));
|
||||
}
|
||||
static IBind create(Bind... binds) {
|
||||
if (binds.length == 1) return binds[0];
|
||||
return new CompoundBind(binds);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user