mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-14 07:35:10 +01:00
Add methods for instantiating storage
This commit is contained in:
@@ -109,14 +109,14 @@ public class MidnightInput {
|
|||||||
|
|
||||||
// Handles the key bindings.
|
// Handles the key bindings.
|
||||||
if (MidnightControlsClient.BINDING_LOOK_UP.isPressed()) {
|
if (MidnightControlsClient.BINDING_LOOK_UP.isPressed()) {
|
||||||
this.handleFlatLook(new AxisStorage(GLFW_GAMEPAD_AXIS_RIGHT_Y, -0.8F, 0d));
|
this.handleFlatLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_Y, -0.8F, 0d));
|
||||||
} else if (MidnightControlsClient.BINDING_LOOK_DOWN.isPressed()) {
|
} else if (MidnightControlsClient.BINDING_LOOK_DOWN.isPressed()) {
|
||||||
this.handleFlatLook(new AxisStorage(GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 0d));
|
this.handleFlatLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 0d));
|
||||||
}
|
}
|
||||||
if (MidnightControlsClient.BINDING_LOOK_LEFT.isPressed()) {
|
if (MidnightControlsClient.BINDING_LOOK_LEFT.isPressed()) {
|
||||||
this.handleFlatLook(new AxisStorage(GLFW_GAMEPAD_AXIS_RIGHT_X, -0.8F, 0d));
|
this.handleFlatLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_X, -0.8F, 0d));
|
||||||
} else if (MidnightControlsClient.BINDING_LOOK_RIGHT.isPressed()) {
|
} else if (MidnightControlsClient.BINDING_LOOK_RIGHT.isPressed()) {
|
||||||
this.handleFlatLook(new AxisStorage(GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 0d));
|
this.handleFlatLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 0d));
|
||||||
}
|
}
|
||||||
|
|
||||||
InputManager.INPUT_MANAGER.tick();
|
InputManager.INPUT_MANAGER.tick();
|
||||||
@@ -262,14 +262,14 @@ public class MidnightInput {
|
|||||||
|
|
||||||
if (pressed != previousState.isPressed()) {
|
if (pressed != previousState.isPressed()) {
|
||||||
state = pressed ? ButtonState.PRESS : ButtonState.RELEASE;
|
state = pressed ? ButtonState.PRESS : ButtonState.RELEASE;
|
||||||
this.handleButton(new ButtonStorage(btn, state));
|
this.handleButton(ButtonStorage.of(btn, state));
|
||||||
if (pressed)
|
if (pressed)
|
||||||
BUTTON_COOLDOWNS.put(btn, 5);
|
BUTTON_COOLDOWNS.put(btn, 5);
|
||||||
} else if (pressed) {
|
} else if (pressed) {
|
||||||
state = ButtonState.REPEAT;
|
state = ButtonState.REPEAT;
|
||||||
if (BUTTON_COOLDOWNS.getOrDefault(btn, 0) == 0) {
|
if (BUTTON_COOLDOWNS.getOrDefault(btn, 0) == 0) {
|
||||||
BUTTON_COOLDOWNS.put(btn, 5);
|
BUTTON_COOLDOWNS.put(btn, 5);
|
||||||
this.handleButton(new ButtonStorage(btn, state));
|
this.handleButton(ButtonStorage.of(btn, state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ public class MidnightInput {
|
|||||||
if (i == GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y)
|
if (i == GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y)
|
||||||
value *= -1.0F;
|
value *= -1.0F;
|
||||||
|
|
||||||
this.handleJoystickAxis(new AxisStorage(axis, value));
|
this.handleJoystickAxis(AxisStorage.of(axis, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -325,7 +325,7 @@ public class MidnightInput {
|
|||||||
int axis = leftJoycon ? ButtonBinding.controller2Button(i) : i;
|
int axis = leftJoycon ? ButtonBinding.controller2Button(i) : i;
|
||||||
float value = buffer.get(i);
|
float value = buffer.get(i);
|
||||||
|
|
||||||
this.handleTriggerAxis(new AxisStorage(axis, value, MidnightControlsConfig.triggerDeadZone));
|
this.handleTriggerAxis(AxisStorage.of(axis, value, MidnightControlsConfig.triggerDeadZone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -352,8 +352,8 @@ public class TouchscreenOverlay extends Screen {
|
|||||||
deltaX = -deltaX;
|
deltaX = -deltaX;
|
||||||
deltaY = -deltaY;
|
deltaY = -deltaY;
|
||||||
}
|
}
|
||||||
input.handleTouchscreenLook(new AxisStorage(GLFW_GAMEPAD_AXIS_RIGHT_Y, (float) deltaY, 0.25d));
|
input.handleTouchscreenLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_Y, (float) deltaY, 0.25d));
|
||||||
input.handleTouchscreenLook(new AxisStorage(GLFW_GAMEPAD_AXIS_RIGHT_X, (float) deltaX, 0.25d));
|
input.handleTouchscreenLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_X, (float) deltaX, 0.25d));
|
||||||
}
|
}
|
||||||
else TouchInput.isDragging = true;
|
else TouchInput.isDragging = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,14 @@ public class AxisStorage {
|
|||||||
public final ButtonState buttonState;
|
public final ButtonState buttonState;
|
||||||
|
|
||||||
// Used for joysticks
|
// Used for joysticks
|
||||||
public AxisStorage(int axis, float value) {
|
public static AxisStorage of(int axis, float value) {
|
||||||
this(axis, value, isLeftAxis(axis) ? MidnightControlsConfig.leftDeadZone : MidnightControlsConfig.rightDeadZone);
|
return new AxisStorage(axis, value, isLeftAxis(axis) ? MidnightControlsConfig.leftDeadZone : MidnightControlsConfig.rightDeadZone);
|
||||||
|
}
|
||||||
|
public static AxisStorage of(int axis, float value, double deadZone) {
|
||||||
|
return new AxisStorage(axis, value, deadZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AxisStorage(int axis, float value, double deadZone) {
|
private AxisStorage(int axis, float value, double deadZone) {
|
||||||
this.axis = axis;
|
this.axis = axis;
|
||||||
this.deadZone = deadZone;
|
this.deadZone = deadZone;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ public class ButtonStorage {
|
|||||||
public final int button;
|
public final int button;
|
||||||
public final ButtonState state;
|
public final ButtonState state;
|
||||||
|
|
||||||
public ButtonStorage(int button, ButtonState state) {
|
public static ButtonStorage of(int button, ButtonState state) {
|
||||||
|
return new ButtonStorage(button, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ButtonStorage(int button, ButtonState state) {
|
||||||
this.button = button;
|
this.button = button;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user