1
0
forked from Clones/Controlify

vanilla keybind override and config system

This commit is contained in:
isXander
2023-02-01 13:27:21 +00:00
parent aad9447325
commit 89c4409371
19 changed files with 441 additions and 64 deletions

View File

@ -21,6 +21,7 @@ public final class Controller {
private ControllerState prevState = ControllerState.EMPTY;
private final ControllerBindings bindings = new ControllerBindings(this);
private final ControllerConfig config = new ControllerConfig();
public Controller(int id, String guid, String name, boolean gamepad) {
this.id = id;
@ -46,10 +47,10 @@ public final class Controller {
prevState = state;
AxesState axesState = AxesState.fromController(this)
.leftJoystickDeadZone(0.2f, 0.2f)
.rightJoystickDeadZone(0.2f, 0.2f)
.leftTriggerDeadZone(0.1f)
.rightTriggerDeadZone(0.1f);
.leftJoystickDeadZone(config().leftStickDeadzone, config().leftStickDeadzone)
.rightJoystickDeadZone(config().rightStickDeadzone, config().rightStickDeadzone)
.leftTriggerDeadZone(config().leftTriggerDeadzone)
.rightTriggerDeadZone(config().rightTriggerDeadzone);
ButtonState buttonState = ButtonState.fromController(this);
state = new ControllerState(axesState, buttonState);
@ -87,15 +88,16 @@ public final class Controller {
return gamepad;
}
public ControllerConfig config() {
return config;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (Controller) obj;
return this.id == that.id &&
Objects.equals(this.guid, that.guid) &&
Objects.equals(this.name, that.name) &&
this.gamepad == that.gamepad;
return Objects.equals(this.guid, that.guid);
}
@Override
@ -103,13 +105,6 @@ public final class Controller {
return Objects.hash(guid);
}
@Override
public String toString() {
return "Controller[" +
"id=" + id + ", " +
"name=" + name + ']';
}
public static Controller byId(int id) {
if (id > GLFW.GLFW_JOYSTICK_LAST)
throw new IllegalArgumentException("Invalid joystick id: " + id);

View File

@ -0,0 +1,33 @@
package dev.isxander.controlify.controller;
import dev.isxander.controlify.config.ControlifyConfig;
public class ControllerConfig {
public static final ControllerConfig DEFAULT = new ControllerConfig();
public float leftStickDeadzone = 0.2f;
public float rightStickDeadzone = 0.2f;
// not sure if triggers need deadzones
public float leftTriggerDeadzone = 0.0f;
public float rightTriggerDeadzone = 0.0f;
public float leftTriggerActivationThreshold = 0.5f;
public float rightTriggerActivationThreshold = 0.5f;
public String customName = null;
public void notifyChanged() {
ControlifyConfig.save();
}
public void overwrite(ControllerConfig from) {
this.leftStickDeadzone = from.leftStickDeadzone;
this.rightStickDeadzone = from.rightStickDeadzone;
this.leftTriggerDeadzone = from.leftTriggerDeadzone;
this.rightTriggerDeadzone = from.rightTriggerDeadzone;
this.leftTriggerActivationThreshold = from.leftTriggerActivationThreshold;
this.rightTriggerActivationThreshold = from.rightTriggerActivationThreshold;
this.customName = from.customName;
}
}