code cleanup, reduce dead zone size, fix mocute mappings

This commit is contained in:
Brendan Robert 2024-03-08 12:15:57 -06:00
parent 847a0ad9f5
commit 5c01149516
2 changed files with 46 additions and 54 deletions

View File

@ -76,10 +76,10 @@ public class Joystick extends Device {
public int button0rapid = -1; public int button0rapid = -1;
public int button1 = -1; public int button1 = -1;
public int button1rapid = -1; public int button1rapid = -1;
public int pause; public int pause = -1;
public boolean xinvert; public boolean xinvert = false;
public int xaxis = -1; public int xaxis = -1;
public boolean yinvert; public boolean yinvert = false;
public int yaxis = -1; public int yaxis = -1;
public int up = -1; public int up = -1;
public int down = -1; public int down = -1;
@ -134,45 +134,33 @@ public class Joystick extends Device {
boolean isHat = source.charAt(0) == 'h'; boolean isHat = source.charAt(0) == 'h';
boolean isNAN = !isAxis && !isButton && !isHat; boolean isNAN = !isAxis && !isButton && !isHat;
int index = isNAN ? -1 : Integer.parseInt(source.substring(isHat ? 3 : 1)); int index = isNAN ? -1 : Integer.parseInt(source.substring(isHat ? 3 : 1));
switch (target) { if (isAxis) {
case "a": switch (target) {
controller.button0 = isButton ? index : 1; case "leftx" -> {
break; controller.xaxis = index;
case "b": controller.xinvert = inverted;
controller.button1 = isButton ? index : 2; }
break; case "lefty" -> {
case "leftx": controller.yaxis = index;
controller.xaxis = isAxis ? index : 0; controller.yinvert = inverted;
controller.xinvert = inverted; }
break; }
case "lefty": } else if (isButton) {
controller.yaxis = isAxis ? index : 1; switch (target) {
controller.yinvert = inverted; case "a" -> controller.button0 = index;
break; case "b" -> controller.button1 = index;
case "dpup": case "x" -> controller.button0rapid = index;
controller.up = isButton ? index : 3; case "y" -> controller.button1rapid = index;
break; case "dpup" -> controller.up = index;
case "dpdown": case "dpdown" -> controller.down = index;
controller.down = isButton ? index : 4; case "dpleft" -> controller.left = index;
break; case "dpright" -> controller.right = index;
case "dpleft": case "start" -> controller.pause = index;
controller.left = isButton ? index : 5; }
break; } else {
case "dpright": if (target.equals("platform")) {
controller.right = isButton ? index : 6;
break;
case "start":
controller.pause = isButton ? index : 7;
break;
case "x":
controller.button0rapid = isButton ? index : 8;
break;
case "y":
controller.button1rapid = isButton ? index : 9;
break;
case "platform":
controller.platform = source; controller.platform = source;
break; }
} }
} }
@ -218,10 +206,13 @@ public class Joystick extends Device {
public int button1 = 2; public int button1 = 2;
@ConfigurableField(name = "Button 1 rapid", shortName = "buttonX", description = "Physical game controller X button") @ConfigurableField(name = "Button 1 rapid", shortName = "buttonX", description = "Physical game controller X button")
public int button1rapid = 4; public int button1rapid = 4;
@ConfigurableField(name = "Manual mapping", shortName = "manual", description = "Use custom controller mapping instead of DB settings")
public boolean useManualMapping = false;
@ConfigurableField(name = "Use D-PAD", shortName = "dpad", description = "Physical game controller enable D-PAD") @ConfigurableField(name = "Use D-PAD", shortName = "dpad", description = "Physical game controller enable D-PAD")
public boolean useDPad = true; public boolean useDPad = true;
@ConfigurableField(name = "Dead Zone", shortName = "deadZone", description = "Dead zone for joystick (0-1)") @ConfigurableField(name = "Dead Zone", shortName = "deadZone", description = "Dead zone for joystick (0-1)")
public static float deadZone = 0.1f; public static float deadZone = 0.05f;
@ConfigurableField(name = "Rapid fire interval (ms)", shortName = "rapidfire", description = "Interval for rapid fire (ms)") @ConfigurableField(name = "Rapid fire interval (ms)", shortName = "rapidfire", description = "Interval for rapid fire (ms)")
public int rapidFireInterval = 16; public int rapidFireInterval = 16;
@ -310,15 +301,15 @@ public class Joystick extends Device {
} }
if (useDPad && controllerMapping != null) { if (useDPad && controllerMapping != null) {
if (buttons.get(controllerMapping.left) != 0) { if (getButton(controllerMapping.left)) {
x = -1; x = -1;
} else if (buttons.get(controllerMapping.right) != 0) { } else if (getButton(controllerMapping.right)) {
x = 1; x = 1;
} }
if (buttons.get(controllerMapping.up) != 0) { if (getButton(controllerMapping.up)) {
y = -1; y = -1;
} else if (buttons.get(controllerMapping.down) != 0) { } else if (getButton(controllerMapping.down)) {
y = 1; y = 1;
} }
} }
@ -381,8 +372,8 @@ public class Joystick extends Device {
private boolean getButton(Integer... choices) { private boolean getButton(Integer... choices) {
for (Integer choice : choices) { for (Integer choice : choices) {
if (choice != null && choice >= 0 && choice < buttons.capacity() && buttons.get(choice) != 0) { if (choice != null && choice >= 0 && choice < buttons.capacity()) {
return true; return buttons.get(choice) != 0;
} }
} }
return false; return false;
@ -390,11 +381,12 @@ public class Joystick extends Device {
private void readButtons() { private void readButtons() {
if (readGLFWJoystick()) { if (readGLFWJoystick()) {
boolean b0 = getButton(controllerMapping != null ? controllerMapping.button0 : null, button0); boolean hasMapping = !useManualMapping && controllerMapping != null;
boolean b0rapid = getButton(controllerMapping != null ? controllerMapping.button0rapid : null, button0rapid); boolean b0 = getButton(hasMapping ? controllerMapping.button0 : null, button0);
boolean b1 = getButton(controllerMapping != null ? controllerMapping.button1 : null, button1); boolean b0rapid = getButton(hasMapping ? controllerMapping.button0rapid : null, button0rapid);
boolean b1rapid = getButton(controllerMapping != null ? controllerMapping.button1rapid : null, button1rapid); boolean b1 = getButton(hasMapping ? controllerMapping.button1 : null, button1);
boolean pause = getButton(controllerMapping != null ? controllerMapping.pause : null); boolean b1rapid = getButton(hasMapping ? controllerMapping.button1rapid : null, button1rapid);
boolean pause = getButton(!hasMapping ? controllerMapping.pause : null);
if (b0rapid) { if (b0rapid) {
if (button0heldSince == 0) { if (button0heldSince == 0) {

View File

@ -2033,4 +2033,4 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,
050000005e040000130b0000ff870001,Xbox Series X Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,misc1:b11,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:iOS, 050000005e040000130b0000ff870001,Xbox Series X Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,misc1:b11,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:iOS,
# Custom Mappings # Custom Mappings
050000004d4f435554452d3033325f00,Mocute-032,a:b3,b:b6,x:b4,y:b5,leftx:a1,lefty:a3,platform:Mac OS X, 050000004d4f435554452d3033325f00,Mocute-032,a:b3,b:b6,x:b11,y:b14,start:b27,leftx:a1,lefty:a3,platform:Mac OS X,