forked from Clones/Controlify
fix bugs:
fix reconnecting controllers are unidentified fix some mod keybinds failing to register fix crash with unmapped joysticks
This commit is contained in:
@ -16,6 +16,7 @@ import org.libsdl.SDL;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractController<S extends ControllerState, C extends ControllerConfig> implements Controller<S, C>, RumbleCapable {
|
||||
@ -24,6 +25,7 @@ public abstract class AbstractController<S extends ControllerState, C extends Co
|
||||
private final String uid;
|
||||
private final String guid;
|
||||
private final ControllerType type;
|
||||
private final ControllerHIDService.ControllerHIDInfo hidInfo;
|
||||
|
||||
protected ControllerBindings<S> bindings;
|
||||
protected C config, defaultConfig;
|
||||
@ -34,6 +36,8 @@ public abstract class AbstractController<S extends ControllerState, C extends Co
|
||||
if (!GLFW.glfwJoystickPresent(joystickId))
|
||||
throw new IllegalArgumentException("Joystick " + joystickId + " is not present and cannot be initialised!");
|
||||
|
||||
this.hidInfo = hidInfo;
|
||||
|
||||
this.joystickId = joystickId;
|
||||
this.guid = GLFW.glfwGetJoystickGUID(joystickId);
|
||||
|
||||
@ -121,6 +125,11 @@ public abstract class AbstractController<S extends ControllerState, C extends Co
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ControllerHIDService.ControllerHIDInfo> hidInfo() {
|
||||
return Optional.of(hidInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -48,6 +48,8 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
||||
RumbleManager rumbleManager();
|
||||
boolean canRumble();
|
||||
|
||||
Optional<ControllerHIDService.ControllerHIDInfo> hidInfo();
|
||||
|
||||
default boolean canBeUsed() {
|
||||
return true;
|
||||
}
|
||||
@ -156,6 +158,11 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
||||
return ControllerType.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ControllerHIDService.ControllerHIDInfo> hidInfo() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "DUMMY";
|
||||
|
@ -105,6 +105,10 @@ public class ControllerHIDService {
|
||||
}
|
||||
}
|
||||
|
||||
public void unconsumeController(ControllerHIDInfo hid) {
|
||||
hid.hidDevice.ifPresent(device -> attachedDevices.remove(device.getPath()));
|
||||
}
|
||||
|
||||
private boolean isController(HidDevice device) {
|
||||
boolean isControllerType = ControllerType.getTypeMap().containsKey(new HIDIdentifier(device.getVendorId(), device.getProductId()));
|
||||
boolean isGenericDesktopControlOrGameControl = device.getUsagePage() == 0x1 || device.getUsagePage() == 0x5;
|
||||
|
@ -6,6 +6,7 @@ import com.google.gson.JsonElement;
|
||||
import dev.isxander.controlify.Controlify;
|
||||
import dev.isxander.controlify.bindings.ControllerBindings;
|
||||
import dev.isxander.controlify.controller.ControllerType;
|
||||
import dev.isxander.controlify.controller.hid.ControllerHIDService;
|
||||
import dev.isxander.controlify.controller.joystick.mapping.JoystickMapping;
|
||||
import dev.isxander.controlify.controller.joystick.mapping.RPJoystickMapping;
|
||||
import dev.isxander.controlify.rumble.RumbleCapable;
|
||||
@ -14,6 +15,7 @@ import dev.isxander.controlify.rumble.RumbleSource;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CompoundJoystickController implements JoystickController<JoystickConfig>, RumbleCapable {
|
||||
private final String uid;
|
||||
@ -177,4 +179,9 @@ public class CompoundJoystickController implements JoystickController<JoystickCo
|
||||
private int getHatCountForJoystick(int joystick) {
|
||||
return GLFW.glfwGetJoystickHats(joystick).capacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ControllerHIDService.ControllerHIDInfo> hidInfo() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class UnmappedJoystickMapping implements JoystickMapping {
|
||||
this.axes[i] = new UnmappedAxis(i, new GenericRenderer.Axis(Integer.toString(i + 1)));
|
||||
}
|
||||
|
||||
this.buttons = new UnmappedButton[axisCount];
|
||||
this.buttons = new UnmappedButton[buttonCount];
|
||||
for (int i = 0; i < buttonCount; i++) {
|
||||
this.buttons[i] = new UnmappedButton(i, new GenericRenderer.Button(Integer.toString(i + 1)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user