1
0
forked from Clones/Controlify

refactor button guide, bindings and controller identification

This commit is contained in:
isXander
2023-02-19 21:56:14 +00:00
parent 23c048f401
commit 0f719c0f45
21 changed files with 334 additions and 220 deletions

View File

@ -10,23 +10,25 @@ import dev.isxander.controlify.gui.DrawSize;
public interface IBind<S extends ControllerState> {
float state(S state);
default boolean held(S state, Controller<S, ?> controller) {
return state(state) > controller.config().buttonActivationThreshold;
default boolean held(S state) {
return state(state) > controller().config().buttonActivationThreshold;
}
void draw(PoseStack matrices, int x, int centerY, Controller<S, ?> controller);
void draw(PoseStack matrices, int x, int centerY);
DrawSize drawSize();
JsonObject toJson();
Controller<S, ?> controller();
@SuppressWarnings("unchecked")
static <T extends ControllerState> IBind<T> fromJson(JsonObject json, Controller<T, ?> controller) {
var type = json.get("type").getAsString();
if (type.equals(EmptyBind.BIND_ID))
return new EmptyBind<>();
if (controller instanceof GamepadController && type.equals(GamepadBind.BIND_ID)) {
return (IBind<T>) GamepadBind.fromJson(json);
if (controller instanceof GamepadController gamepad && type.equals(GamepadBinds.BIND_ID)) {
return GamepadBinds.fromJson(json).map(bind -> (IBind<T>) bind.forGamepad(gamepad)).orElse(new EmptyBind<>());
} else if (controller instanceof JoystickController joystick) {
return (IBind<T>) switch (type) {
case JoystickButtonBind.BIND_ID -> JoystickButtonBind.fromJson(json, joystick);