mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 07:15:10 +01:00
Add methods for instantiating storage
This commit is contained in:
@@ -109,14 +109,14 @@ public class MidnightInput {
|
||||
|
||||
// Handles the key bindings.
|
||||
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()) {
|
||||
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()) {
|
||||
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()) {
|
||||
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();
|
||||
@@ -262,14 +262,14 @@ public class MidnightInput {
|
||||
|
||||
if (pressed != previousState.isPressed()) {
|
||||
state = pressed ? ButtonState.PRESS : ButtonState.RELEASE;
|
||||
this.handleButton(new ButtonStorage(btn, state));
|
||||
this.handleButton(ButtonStorage.of(btn, state));
|
||||
if (pressed)
|
||||
BUTTON_COOLDOWNS.put(btn, 5);
|
||||
} else if (pressed) {
|
||||
state = ButtonState.REPEAT;
|
||||
if (BUTTON_COOLDOWNS.getOrDefault(btn, 0) == 0) {
|
||||
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)
|
||||
value *= -1.0F;
|
||||
|
||||
this.handleJoystickAxis(new AxisStorage(axis, value));
|
||||
this.handleJoystickAxis(AxisStorage.of(axis, value));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -325,7 +325,7 @@ public class MidnightInput {
|
||||
int axis = leftJoycon ? ButtonBinding.controller2Button(i) : 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;
|
||||
deltaY = -deltaY;
|
||||
}
|
||||
input.handleTouchscreenLook(new AxisStorage(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_Y, (float) deltaY, 0.25d));
|
||||
input.handleTouchscreenLook(AxisStorage.of(GLFW_GAMEPAD_AXIS_RIGHT_X, (float) deltaX, 0.25d));
|
||||
}
|
||||
else TouchInput.isDragging = true;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,14 @@ public class AxisStorage {
|
||||
public final ButtonState buttonState;
|
||||
|
||||
// Used for joysticks
|
||||
public AxisStorage(int axis, float value) {
|
||||
this(axis, value, isLeftAxis(axis) ? MidnightControlsConfig.leftDeadZone : MidnightControlsConfig.rightDeadZone);
|
||||
public static AxisStorage of(int axis, float value) {
|
||||
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.deadZone = deadZone;
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ public class ButtonStorage {
|
||||
public final int button;
|
||||
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.state = state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user