mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add Joystick:set/getPlayerIndex
This commit is contained in:
@@ -165,6 +165,9 @@ public:
|
||||
|
||||
virtual bool isDown(const std::vector<int> &buttonlist) const = 0;
|
||||
|
||||
virtual void setPlayerIndex(int index) = 0;
|
||||
virtual int getPlayerIndex() const = 0;
|
||||
|
||||
virtual bool openGamepad(int deviceindex) = 0;
|
||||
virtual bool isGamepad() const = 0;
|
||||
|
||||
|
||||
@@ -195,6 +195,30 @@ bool Joystick::isDown(const std::vector<int> &buttonlist) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void Joystick::setPlayerIndex(int index)
|
||||
{
|
||||
if (!isConnected())
|
||||
return;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
||||
SDL_JoystickSetPlayerIndex(joyhandle, index);
|
||||
#else
|
||||
LOVE_UNUSED(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Joystick::getPlayerIndex() const
|
||||
{
|
||||
if (!isConnected())
|
||||
return -1;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
||||
return SDL_JoystickGetPlayerIndex(joyhandle);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Joystick::openGamepad(int deviceindex)
|
||||
{
|
||||
if (!SDL_IsGameController(deviceindex))
|
||||
|
||||
@@ -61,6 +61,9 @@ public:
|
||||
|
||||
bool isDown(const std::vector<int> &buttonlist) const override;
|
||||
|
||||
void setPlayerIndex(int index) override;
|
||||
int getPlayerIndex() const override;
|
||||
|
||||
bool openGamepad(int deviceindex) override;
|
||||
bool isGamepad() const override;
|
||||
|
||||
|
||||
@@ -171,6 +171,22 @@ int w_Joystick_isDown(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joystick_setPlayerIndex(lua_State *L)
|
||||
{
|
||||
Joystick *j = luax_checkjoystick(L, 1);
|
||||
int index = (int) luaL_checkinteger(L, 2) - 1;
|
||||
j->setPlayerIndex(index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Joystick_getPlayerIndex(lua_State *L)
|
||||
{
|
||||
Joystick *j = luax_checkjoystick(L, 1);
|
||||
int index = j->getPlayerIndex();
|
||||
lua_pushinteger(L, index >= 0 ? index + 1 : index);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joystick_isGamepad(lua_State *L)
|
||||
{
|
||||
Joystick *j = luax_checkjoystick(L, 1);
|
||||
@@ -366,6 +382,8 @@ static const luaL_Reg w_Joystick_functions[] =
|
||||
{ "getAxes", w_Joystick_getAxes },
|
||||
{ "getHat", w_Joystick_getHat },
|
||||
{ "isDown", w_Joystick_isDown },
|
||||
{ "setPlayerIndex", w_Joystick_setPlayerIndex },
|
||||
{ "getPlayerIndex", w_Joystick_getPlayerIndex },
|
||||
|
||||
{ "isGamepad", w_Joystick_isGamepad },
|
||||
{ "getGamepadType", w_Joystick_getGamepadType },
|
||||
|
||||
Reference in New Issue
Block a user