Skip to content

Commit

Permalink
Add switch pro controller mappings and gamepad.getInputLabel (#2254)
Browse files Browse the repository at this point in the history
Co-authored-by: Jens Fischer <[email protected]>
  • Loading branch information
Geokureli and Gama11 authored Jun 7, 2020
1 parent 7bcef2a commit d42a07d
Show file tree
Hide file tree
Showing 15 changed files with 844 additions and 33 deletions.
51 changes: 33 additions & 18 deletions flixel/input/gamepad/FlxGamepad.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import flixel.input.gamepad.mappings.OUYAMapping;
import flixel.input.gamepad.mappings.PS4Mapping;
import flixel.input.gamepad.mappings.PSVitaMapping;
import flixel.input.gamepad.mappings.WiiRemoteMapping;
import flixel.input.gamepad.mappings.SwitchProMapping;
import flixel.input.gamepad.mappings.SwitchJoyconLeftMapping;
import flixel.input.gamepad.mappings.SwitchJoyconRightMapping;
import flixel.input.gamepad.mappings.XInputMapping;
import flixel.math.FlxVector;
import flixel.util.FlxDestroyUtil;
Expand Down Expand Up @@ -309,24 +312,9 @@ class FlxGamepad implements IFlxDestroyable
{
return switch (ID)
{
case FlxGamepadInputID.ANY:
switch (Status)
{
case PRESSED: pressed.ANY;
case JUST_PRESSED: justPressed.ANY;
case RELEASED: released.ANY;
case JUST_RELEASED: justReleased.ANY;
}
case FlxGamepadInputID.NONE:
switch (Status)
{
case PRESSED: pressed.NONE;
case JUST_PRESSED: justPressed.NONE;
case RELEASED: released.NONE;
case JUST_RELEASED: justReleased.NONE;
}
default:
checkStatusRaw(mapping.getRawID(ID), Status);
case FlxGamepadInputID.ANY: anyButton(Status);
case FlxGamepadInputID.NONE: !anyButton(Status);
default: checkStatusRaw(mapping.getRawID(ID), Status);
}
}

Expand Down Expand Up @@ -837,6 +825,9 @@ class FlxGamepad implements IFlxDestroyable
case MAYFLASH_WII_REMOTE: new MayflashWiiRemoteMapping(attachment);
case WII_REMOTE: new WiiRemoteMapping(attachment);
case MFI: new MFiMapping(attachment);
case SWITCH_PRO: new SwitchProMapping(attachment);
case SWITCH_JOYCON_LEFT: new SwitchJoyconLeftMapping(attachment);
case SWITCH_JOYCON_RIGHT: new SwitchJoyconRightMapping(attachment);
// default to XInput if we don't have a mapping for this
case _: new XInputMapping(attachment);
}
Expand Down Expand Up @@ -875,6 +866,14 @@ class FlxGamepad implements IFlxDestroyable
{
return _deadZone = deadZone;
}

/**
* @since 4.8.0
*/
public inline function getInputLabel(id:FlxGamepadInputID)
{
return mapping.getInputLabel(id);
}

public function toString():String
{
Expand Down Expand Up @@ -911,6 +910,22 @@ enum FlxGamepadModel
MAYFLASH_WII_REMOTE;
WII_REMOTE;
MFI;

/**
* @since 4.8.0
*/
SWITCH_PRO; // also dual joycons

/**
* @since 4.8.0
*/
SWITCH_JOYCON_LEFT;

/**
* @since 4.8.0
*/
SWITCH_JOYCON_RIGHT;

UNKNOWN;
}

Expand Down
38 changes: 24 additions & 14 deletions flixel/input/gamepad/FlxGamepadManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,30 @@ class FlxGamepadManager implements IFlxInputManager
// and the most popular tools just turn it into a 360 controller

name = name.toLowerCase().remove("-").remove("_");
return if (name.contains("ouya")) OUYA; // "OUYA Game Controller"
else if (name.contains("wireless controller") || name.contains("ps4")) PS4; // "Wireless Controller" or "PS4 controller"
else if (name.contains("logitech")) LOGITECH; else if (name.contains("xbox") && name.contains("360")) XINPUT; else if (name.contains("xinput"))
XINPUT;
else if (name.contains("nintendo rvlcnt01tr"))
WII_REMOTE; // WiiRemote with motion plus
else if (name.contains("nintendo rvlcnt01"))
WII_REMOTE; // WiiRemote w/o motion plus
else if (name.contains("mayflash wiimote pc adapter"))
MAYFLASH_WII_REMOTE; // WiiRemote paired to MayFlash DolphinBar (with or w/o motion plus)
else if (name.contains("mfi"))
MFI;
else
UNKNOWN;
return if (name.contains("ouya"))
OUYA; // "OUYA Game Controller"
else if (name.contains("wireless controller") || name.contains("ps4"))
PS4; // "Wireless Controller" or "PS4 controller"
else if (name.contains("logitech"))
LOGITECH;
else if ((name.contains("xbox") && name.contains("360")) || name.contains("xinput"))
XINPUT;
else if (name.contains("nintendo rvlcnt01tr"))
WII_REMOTE; // WiiRemote with motion plus
else if (name.contains("nintendo rvlcnt01"))
WII_REMOTE; // WiiRemote w/o motion plus
else if (name.contains("mayflash wiimote pc adapter"))
MAYFLASH_WII_REMOTE; // WiiRemote paired to MayFlash DolphinBar (with or w/o motion plus)
else if (name.contains("mfi"))
MFI;
else if (name.contains("pro controller") || name.contains("joycon l+r"))
SWITCH_PRO;
else if (name.contains("joycon (l)"))
SWITCH_JOYCON_LEFT;
else if (name.contains("joycon (r)"))
SWITCH_JOYCON_RIGHT;
else
UNKNOWN;
}

function removeGamepad(Device:GameInputDevice):Void
Expand Down
62 changes: 62 additions & 0 deletions flixel/input/gamepad/id/SwitchJoyconLeftID.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package flixel.input.gamepad.id;

import flixel.input.gamepad.FlxGamepadAnalogStick;

/**
* IDs for Switch's Left JoyCon controllers
*
*-------
* NOTES
*-------
*
* WINDOWS: untested.
*
* LINUX: untested.
*
* MAC: Worked on html out of box for me when connected via microUSB cable or Bluetooth.
* Flash and neko couldn't detect the controller via bluetooth,
* which is weird because The pro worked wirelessly.
*
* @since 4.8.0
*/
class SwitchJoyconLeftID
{
#if flash
public static inline var UP:Int = 8;
public static inline var LEFT:Int = 9;
public static inline var DOWN:Int = 10;
public static inline var RIGHT:Int = 11;
public static inline var SL:Int = 12;
public static inline var SR:Int = 13;
public static inline var ZL:Int = 14;
public static inline var L:Int = 15;
public static inline var MINUS:Int = 17;
public static inline var CAPTURE:Int = 21;
public static inline var LEFT_STICK_CLICK:Int = 22;
public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, {
up: 24,
down: 25,
left: 26,
right: 27
});
#else
public static inline var ZL:Int = 4;
public static inline var DOWN:Int = 6;
public static inline var RIGHT:Int = 7;
public static inline var LEFT:Int = 8;
public static inline var UP:Int = 9;
public static inline var L:Int = 10;
public static inline var MINUS:Int = 12;
public static inline var LEFT_STICK_CLICK:Int = 13;
public static inline var SL:Int = 15;
public static inline var SR:Int = 16;
public static inline var CAPTURE:Int = 21;
public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, {
up: 22,
down: 23,
left: 24,
right: 25
});
#end

}
69 changes: 69 additions & 0 deletions flixel/input/gamepad/id/SwitchJoyconRightID.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package flixel.input.gamepad.id;

import flixel.input.gamepad.FlxGamepadAnalogStick;

/**
* IDs for Switch's Right JoyCon controllers
*
*-------
* NOTES
*-------
*
* WINDOWS: untested.
*
* LINUX: untested.
*
* MAC: Worked on html out of box for me when connected via microUSB cable or Bluetooth.
* Flash and neko couldn't detect the controller via bluetooth,
* which is weird because The pro worked wirelessly.
*
* @since 4.8.0
*/
class SwitchJoyconRightID
{
#if flash
public static inline var A:Int = 8;
public static inline var B:Int = 9;
public static inline var X:Int = 10;
public static inline var Y:Int = 11;
public static inline var SL:Int = 12;
public static inline var SR:Int = 13;
public static inline var ZR:Int = 15;
public static inline var R:Int = 16;
public static inline var PLUS:Int = 17;
public static inline var HOME:Int = 20;
public static inline var CAPTURE:Int = 21;
public static inline var LEFT_STICK_CLICK:Int = 22;
public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, {
up: 24,
down: 25,
left: 26,
right: 27
});
public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, {
up: 28,
down: 29,
left: 30,
right: 31
});
#else
public static inline var ZR:Int = 5;
public static inline var B:Int = 6;
public static inline var A:Int = 7;
public static inline var Y:Int = 8;
public static inline var X:Int = 9;
public static inline var R:Int = 10;
public static inline var HOME:Int = 11;
public static inline var PLUS:Int = 12;
public static inline var LEFT_STICK_CLICK:Int = 13;
public static inline var SL:Int = 15;
public static inline var SR:Int = 16;
public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, {
up: 22,
down: 23,
left: 24,
right: 25
});
#end

}
86 changes: 86 additions & 0 deletions flixel/input/gamepad/id/SwitchProID.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package flixel.input.gamepad.id;

import flixel.input.gamepad.FlxGamepadAnalogStick;

/**
* IDs for Switch Pro controllers
*
*-------
* NOTES
*-------
*
* WINDOWS: untested.
*
* LINUX: untested
*
* MAC: Worked out of box for me when connected via microUSB cable or Bluetooth
*
* @since 4.8.0
*/
class SwitchProID
{
#if flash
public static inline var DPAD_UP:Int = 4;
public static inline var DPAD_DOWN:Int = 5;
public static inline var DPAD_LEFT:Int = 6;
public static inline var DPAD_RIGHT:Int = 7;
public static inline var A:Int = 8;
public static inline var B:Int = 9;
public static inline var X:Int = 10;
public static inline var Y:Int = 11;
public static inline var L:Int = 12;
public static inline var R:Int = 13;
public static inline var ZL:Int = 14;
public static inline var ZR:Int = 15;
public static inline var MINUS:Int = 16;
public static inline var PLUS:Int = 17;
public static inline var HOME:Int = 20;
public static inline var CAPTURE:Int = 21;
public static inline var LEFT_STICK_CLICK:Int = 22;
public static inline var RIGHT_STICK_CLICK:Int = 23;
public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, {
up: 24,
down: 25,
left: 26,
right: 27
});
public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, {
up: 28,
down: 29,
left: 30,
right: 31
});
#else
public static inline var ZL:Int = 4;
public static inline var ZR:Int = 5;
public static inline var B:Int = 6;
public static inline var A:Int = 7;
public static inline var Y:Int = 8;
public static inline var X:Int = 9;
public static inline var MINUS:Int = 10;
public static inline var HOME:Int = 11;
public static inline var PLUS:Int = 12;
public static inline var LEFT_STICK_CLICK:Int = 13;
public static inline var RIGHT_STICK_CLICK:Int = 14;
public static inline var L:Int = 15;
public static inline var R:Int = 16;
public static inline var DPAD_UP:Int = 17;
public static inline var DPAD_DOWN:Int = 18;
public static inline var DPAD_LEFT:Int = 19;
public static inline var DPAD_RIGHT:Int = 20;
public static inline var CAPTURE:Int = 21;
public static var LEFT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(0, 1, {
up: 22,
down: 23,
left: 24,
right: 25
});
public static var RIGHT_ANALOG_STICK(default, null) = new FlxGamepadAnalogStick(2, 3, {
up: 26,
down: 27,
left: 28,
right: 29
});
#end

}
Loading

0 comments on commit d42a07d

Please sign in to comment.