forked from Clones/Controlify
pre1 and less sodium stuff cuz i got a pr merged
This commit is contained in:
@ -14,7 +14,7 @@ import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractController<S extends ControllerState, C extends ControllerConfig> implements Controller<S, C> {
|
||||
private final int joystickId;
|
||||
protected final int joystickId;
|
||||
protected String name;
|
||||
private final String uid;
|
||||
private final String guid;
|
||||
@ -47,11 +47,6 @@ public abstract class AbstractController<S extends ControllerState, C extends Co
|
||||
this.bindings = new ControllerBindings<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int joystickId() {
|
||||
return this.joystickId;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
if (config().customName != null)
|
||||
return config().customName;
|
||||
|
@ -15,7 +15,6 @@ import java.util.Map;
|
||||
|
||||
public interface Controller<S extends ControllerState, C extends ControllerConfig> {
|
||||
String uid();
|
||||
int joystickId();
|
||||
String guid();
|
||||
|
||||
ControllerBindings<S> bindings();
|
||||
@ -75,11 +74,6 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int joystickId() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String guid() {
|
||||
return "DUMMY";
|
||||
|
@ -10,28 +10,12 @@ import org.quiltmc.json5.JsonReader;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ControllerType {
|
||||
public record ControllerType(String friendlyName, String identifier) {
|
||||
public static final ControllerType UNKNOWN = new ControllerType("Unknown", "unknown");
|
||||
|
||||
private static Map<HIDIdentifier, ControllerType> typeMap = null;
|
||||
private static final ResourceLocation hidDbLocation = new ResourceLocation("controlify", "controllers/controller_identification.json5");
|
||||
|
||||
private final String friendlyName;
|
||||
private final String identifier;
|
||||
|
||||
private ControllerType(String friendlyName, String identifier) {
|
||||
this.friendlyName = friendlyName;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String friendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
public String identifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public static ControllerType getTypeForHID(HIDIdentifier hid) {
|
||||
if (typeMap != null) return typeMap.getOrDefault(hid, UNKNOWN);
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
|
||||
|
||||
GLFWGamepadState getGamepadState() {
|
||||
GLFWGamepadState state = GLFWGamepadState.create();
|
||||
GLFW.glfwGetGamepadState(joystickId(), state);
|
||||
GLFW.glfwGetGamepadState(joystickId, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class JoystickController extends AbstractController<JoystickState, Joysti
|
||||
@Override
|
||||
public void updateState() {
|
||||
prevState = state;
|
||||
state = JoystickState.fromJoystick(this);
|
||||
state = JoystickState.fromJoystick(this, joystickId);
|
||||
}
|
||||
|
||||
public JoystickMapping mapping() {
|
||||
|
@ -24,7 +24,7 @@ public class JoystickState implements ControllerState {
|
||||
private final List<Boolean> buttons;
|
||||
private final List<HatState> hats;
|
||||
|
||||
private JoystickState(JoystickMapping mapping, List<Float> axes, List<Float> rawAxes, List<Boolean> buttons, List<HatState> hats) {
|
||||
protected JoystickState(JoystickMapping mapping, List<Float> axes, List<Float> rawAxes, List<Boolean> buttons, List<HatState> hats) {
|
||||
this.mapping = mapping;
|
||||
this.axes = axes;
|
||||
this.rawAxes = rawAxes;
|
||||
@ -58,8 +58,8 @@ public class JoystickState implements ControllerState {
|
||||
|| hats().stream().anyMatch(hat -> hat != HatState.CENTERED);
|
||||
}
|
||||
|
||||
public static JoystickState fromJoystick(JoystickController joystick) {
|
||||
FloatBuffer axesBuffer = GLFW.glfwGetJoystickAxes(joystick.joystickId());
|
||||
public static JoystickState fromJoystick(JoystickController joystick, int joystickId) {
|
||||
FloatBuffer axesBuffer = GLFW.glfwGetJoystickAxes(joystickId);
|
||||
List<Float> axes = new ArrayList<>();
|
||||
List<Float> rawAxes = new ArrayList<>();
|
||||
if (axesBuffer != null) {
|
||||
@ -76,7 +76,7 @@ public class JoystickState implements ControllerState {
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(joystick.joystickId());
|
||||
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(joystickId);
|
||||
List<Boolean> buttons = new ArrayList<>();
|
||||
if (buttonBuffer != null) {
|
||||
while (buttonBuffer.hasRemaining()) {
|
||||
@ -84,7 +84,7 @@ public class JoystickState implements ControllerState {
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuffer hatBuffer = GLFW.glfwGetJoystickHats(joystick.joystickId());
|
||||
ByteBuffer hatBuffer = GLFW.glfwGetJoystickHats(joystickId);
|
||||
List<JoystickState.HatState> hats = new ArrayList<>();
|
||||
if (hatBuffer != null) {
|
||||
while (hatBuffer.hasRemaining()) {
|
||||
|
Reference in New Issue
Block a user