mirror of
https://github.com/love2d/love.git
synced 2026-08-12 00:20:52 +02:00
Add Joystick:getJoystickType.
This commit is contained in:
@@ -25,6 +25,7 @@ Released: N/A
|
||||
* Added love.audio.getPlaybackDevice, love.audio.getPlaybackDevices, and love.audio.setPlaybackDevice.
|
||||
* Added love.keyboard.isModifierActive.
|
||||
* Added Joystick:setPlayerIndex and Joystick:getPlayerIndex.
|
||||
* Added Joystick:getJoystickType.
|
||||
* Added Joystick:getGamepadType.
|
||||
* Added Joystick:hasSensor.
|
||||
* Added Joystick:isSensorEnabled and Joystick:setSensorEnabled.
|
||||
|
||||
@@ -56,6 +56,21 @@ STRINGMAP_CLASS_BEGIN(Joystick, Joystick::Hat, Joystick::HAT_MAX_ENUM, hat)
|
||||
}
|
||||
STRINGMAP_CLASS_END(Joystick, Joystick::Hat, Joystick::HAT_MAX_ENUM, hat)
|
||||
|
||||
STRINGMAP_CLASS_BEGIN(Joystick, Joystick::JoystickType, Joystick::JOYSTICK_TYPE_MAX_ENUM, joystickType)
|
||||
{
|
||||
{ "unknown", Joystick::JOYSTICK_TYPE_UNKNOWN },
|
||||
{ "gamepad", Joystick::JOYSTICK_TYPE_GAMEPAD },
|
||||
{ "wheel", Joystick::JOYSTICK_TYPE_WHEEL },
|
||||
{ "arcadestick", Joystick::JOYSTICK_TYPE_ARCADE_STICK },
|
||||
{ "flightstick", Joystick::JOYSTICK_TYPE_FLIGHT_STICK },
|
||||
{ "dancepad", Joystick::JOYSTICK_TYPE_DANCE_PAD },
|
||||
{ "guitar", Joystick::JOYSTICK_TYPE_GUITAR },
|
||||
{ "drumkit", Joystick::JOYSTICK_TYPE_DRUM_KIT },
|
||||
{ "arcadepad", Joystick::JOYSTICK_TYPE_ARCADE_PAD },
|
||||
{ "throttle", Joystick::JOYSTICK_TYPE_THROTTLE },
|
||||
}
|
||||
STRINGMAP_CLASS_END(Joystick, Joystick::JoystickType, Joystick::JOYSTICK_TYPE_MAX_ENUM, joystickType)
|
||||
|
||||
STRINGMAP_CLASS_BEGIN(Joystick, Joystick::GamepadType, Joystick::GAMEPAD_TYPE_MAX_ENUM, gamepadType)
|
||||
{
|
||||
{ "unknown", Joystick::GAMEPAD_TYPE_UNKNOWN },
|
||||
|
||||
@@ -59,6 +59,21 @@ public:
|
||||
HAT_MAX_ENUM = 16
|
||||
};
|
||||
|
||||
enum JoystickType
|
||||
{
|
||||
JOYSTICK_TYPE_UNKNOWN,
|
||||
JOYSTICK_TYPE_GAMEPAD,
|
||||
JOYSTICK_TYPE_WHEEL,
|
||||
JOYSTICK_TYPE_ARCADE_STICK,
|
||||
JOYSTICK_TYPE_FLIGHT_STICK,
|
||||
JOYSTICK_TYPE_DANCE_PAD,
|
||||
JOYSTICK_TYPE_GUITAR,
|
||||
JOYSTICK_TYPE_DRUM_KIT,
|
||||
JOYSTICK_TYPE_ARCADE_PAD,
|
||||
JOYSTICK_TYPE_THROTTLE,
|
||||
JOYSTICK_TYPE_MAX_ENUM
|
||||
};
|
||||
|
||||
enum GamepadType
|
||||
{
|
||||
GAMEPAD_TYPE_UNKNOWN,
|
||||
@@ -164,6 +179,8 @@ public:
|
||||
|
||||
virtual const char *getName() const = 0;
|
||||
|
||||
virtual JoystickType getJoystickType() const = 0;
|
||||
|
||||
virtual int getAxisCount() const = 0;
|
||||
virtual int getButtonCount() const = 0;
|
||||
virtual int getHatCount() const = 0;
|
||||
@@ -207,6 +224,7 @@ public:
|
||||
virtual std::vector<float> getSensorData(Sensor::SensorType type) const = 0;
|
||||
|
||||
STRINGMAP_CLASS_DECLARE(Hat);
|
||||
STRINGMAP_CLASS_DECLARE(JoystickType);
|
||||
STRINGMAP_CLASS_DECLARE(GamepadType);
|
||||
STRINGMAP_CLASS_DECLARE(GamepadAxis);
|
||||
STRINGMAP_CLASS_DECLARE(GamepadButton);
|
||||
|
||||
@@ -46,6 +46,7 @@ Joystick::Joystick(int id)
|
||||
: joyhandle(nullptr)
|
||||
, controller(nullptr)
|
||||
, haptic(nullptr)
|
||||
, joystickType(JOYSTICK_TYPE_UNKNOWN)
|
||||
, instanceid(-1)
|
||||
, id(id)
|
||||
, vibration()
|
||||
@@ -96,6 +97,40 @@ bool Joystick::open(int deviceindex)
|
||||
|
||||
if (joyname)
|
||||
name = joyname;
|
||||
|
||||
switch (SDL_JoystickGetType(joyhandle))
|
||||
{
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
joystickType = JOYSTICK_TYPE_GAMEPAD;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_WHEEL:
|
||||
joystickType = JOYSTICK_TYPE_WHEEL;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_STICK:
|
||||
joystickType = JOYSTICK_TYPE_ARCADE_STICK;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_FLIGHT_STICK:
|
||||
joystickType = JOYSTICK_TYPE_FLIGHT_STICK;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DANCE_PAD:
|
||||
joystickType = JOYSTICK_TYPE_DANCE_PAD;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_GUITAR:
|
||||
joystickType = JOYSTICK_TYPE_GUITAR;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DRUM_KIT:
|
||||
joystickType = JOYSTICK_TYPE_DRUM_KIT;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_PAD:
|
||||
joystickType = JOYSTICK_TYPE_ARCADE_PAD;
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_THROTTLE:
|
||||
joystickType = JOYSTICK_TYPE_THROTTLE;
|
||||
break;
|
||||
default:
|
||||
joystickType = JOYSTICK_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isConnected();
|
||||
@@ -129,6 +164,11 @@ const char *Joystick::getName() const
|
||||
return name.c_str();
|
||||
}
|
||||
|
||||
Joystick::JoystickType Joystick::getJoystickType() const
|
||||
{
|
||||
return joystickType;
|
||||
}
|
||||
|
||||
int Joystick::getAxisCount() const
|
||||
{
|
||||
return isConnected() ? SDL_JoystickNumAxes(joyhandle) : 0;
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
|
||||
const char *getName() const override;
|
||||
|
||||
JoystickType getJoystickType() const override;
|
||||
|
||||
int getAxisCount() const override;
|
||||
int getButtonCount() const override;
|
||||
int getHatCount() const override;
|
||||
@@ -113,6 +115,8 @@ private:
|
||||
SDL_GameController *controller;
|
||||
SDL_Haptic *haptic;
|
||||
|
||||
JoystickType joystickType;
|
||||
|
||||
SDL_JoystickID instanceid;
|
||||
std::string pguid;
|
||||
int id;
|
||||
|
||||
@@ -86,6 +86,15 @@ int w_Joystick_getDeviceInfo(lua_State *L)
|
||||
return 3;
|
||||
}
|
||||
|
||||
int w_Joystick_getJoystickType(lua_State *L)
|
||||
{
|
||||
Joystick *j = luax_checkjoystick(L, 1);
|
||||
const char* str = "unknown";
|
||||
Joystick::getConstant(j->getJoystickType(), str);
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joystick_getAxisCount(lua_State *L)
|
||||
{
|
||||
Joystick *j = luax_checkjoystick(L, 1);
|
||||
@@ -448,6 +457,7 @@ static const luaL_Reg w_Joystick_functions[] =
|
||||
{ "getID", w_Joystick_getID },
|
||||
{ "getGUID", w_Joystick_getGUID },
|
||||
{ "getDeviceInfo", w_Joystick_getDeviceInfo },
|
||||
{ "getJoystickType", w_Joystick_getJoystickType },
|
||||
{ "getAxisCount", w_Joystick_getAxisCount },
|
||||
{ "getButtonCount", w_Joystick_getButtonCount },
|
||||
{ "getHatCount", w_Joystick_getHatCount },
|
||||
|
||||
Reference in New Issue
Block a user