1
0
forked from Clones/Controlify

🎮📳 Controller Vibration! (#38)

This commit is contained in:
Xander
2023-04-04 17:17:01 +01:00
committed by GitHub
parent 2bf7cf4792
commit ebbc549e32
32 changed files with 686 additions and 42 deletions

View File

@ -7,10 +7,12 @@ import dev.isxander.controlify.controller.gamepad.GamepadController;
import dev.isxander.controlify.controller.hid.ControllerHIDService;
import dev.isxander.controlify.controller.joystick.SingleJoystickController;
import dev.isxander.controlify.debug.DebugProperties;
import dev.isxander.controlify.rumble.RumbleManager;
import org.lwjgl.glfw.GLFW;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public interface Controller<S extends ControllerState, C extends ControllerConfig> {
String uid();
@ -33,15 +35,22 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
void updateState();
void clearState();
RumbleManager rumbleManager();
default boolean canBeUsed() {
return true;
}
default void close() {
}
Map<String, Controller<?, ?>> CONTROLLERS = new HashMap<>();
static Controller<?, ?> createOrGet(int joystickId, ControllerHIDService.ControllerHIDInfo hidInfo) {
if (CONTROLLERS.containsKey(hidInfo.createControllerUID())) {
return CONTROLLERS.get(hidInfo.createControllerUID());
Optional<String> uid = hidInfo.createControllerUID();
if (uid.isPresent() && CONTROLLERS.containsKey(uid.get())) {
return CONTROLLERS.get(uid.get());
}
if (GLFW.glfwJoystickIsGamepad(joystickId) && !DebugProperties.FORCE_JOYSTICK) {
@ -55,6 +64,11 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
return controller;
}
static void remove(Controller<?, ?> controller) {
CONTROLLERS.remove(controller.uid());
controller.close();
}
Controller<?, ?> DUMMY = new Controller<>() {
private final ControllerBindings<ControllerState> bindings = new ControllerBindings<>(this);
private final ControllerConfig config = new ControllerConfig() {
@ -133,5 +147,10 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
public void clearState() {
}
@Override
public RumbleManager rumbleManager() {
return null;
}
};
}