forked from Clones/Controlify
better binding api and look sensitivity
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package dev.isxander.controlify;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import dev.isxander.controlify.compatibility.screen.ScreenProcessorProvider;
|
||||
import dev.isxander.controlify.config.ControlifyConfig;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
@ -9,8 +10,10 @@ import dev.isxander.controlify.ingame.InGameInputHandler;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class Controlify {
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static Controlify instance = null;
|
||||
|
||||
private Controller currentController;
|
||||
@ -22,7 +25,7 @@ public class Controlify {
|
||||
for (int i = 0; i < GLFW.GLFW_JOYSTICK_LAST; i++) {
|
||||
if (GLFW.glfwJoystickPresent(i)) {
|
||||
setCurrentController(Controller.byId(i));
|
||||
System.out.println("Connected: " + currentController.name());
|
||||
LOGGER.info("Controller found: " + currentController.name());
|
||||
this.setCurrentInputMode(InputMode.CONTROLLER);
|
||||
}
|
||||
}
|
||||
@ -32,18 +35,17 @@ public class Controlify {
|
||||
|
||||
// listen for new controllers
|
||||
GLFW.glfwSetJoystickCallback((jid, event) -> {
|
||||
System.out.println("Event: " + event);
|
||||
if (event == GLFW.GLFW_CONNECTED) {
|
||||
setCurrentController(Controller.byId(jid));
|
||||
System.out.println("Connected: " + currentController.name());
|
||||
LOGGER.info("Controller connected: " + currentController.name());
|
||||
this.setCurrentInputMode(InputMode.CONTROLLER);
|
||||
|
||||
ControlifyConfig.load(); // load config again if a configuration already exists for this controller
|
||||
ControlifyConfig.save(); // save config if it doesn't exist
|
||||
} else if (event == GLFW.GLFW_DISCONNECTED) {
|
||||
Controller.CONTROLLERS.remove(jid);
|
||||
var controller = Controller.CONTROLLERS.remove(jid);
|
||||
setCurrentController(Controller.CONTROLLERS.values().stream().filter(Controller::connected).findFirst().orElse(null));
|
||||
System.out.println("Disconnected: " + jid);
|
||||
LOGGER.info("Controller disconnected: " + controller.name());
|
||||
this.setCurrentInputMode(currentController == null ? InputMode.KEYBOARD_MOUSE : InputMode.CONTROLLER);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user