1
0
forked from Clones/Controlify

better binding api and look sensitivity

This commit is contained in:
isXander
2023-02-01 15:04:18 +00:00
parent 4ea05b9dbf
commit b77a5361ad
10 changed files with 64 additions and 36 deletions

View File

@ -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);
}
});