Add methods for instantiating storage

This commit is contained in:
Martin Prokoph
2024-07-22 16:20:38 +02:00
parent 78ada44d73
commit dbb6e926e6
4 changed files with 21 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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