mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
love.joystick.isDown gets multiple arguments too
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ LOVE 0.7.2 [Game Slave]
|
||||
|
||||
* Added Framebuffer:get/setWrap.
|
||||
* Added love.event.clear.
|
||||
* Added support for any number of arguments to love.keyboard.isDown and love.mouse.isDown.
|
||||
* Added support for any number of arguments to love.keyboard.isDown, love.mouse.isDown and love.joystick.isDown.
|
||||
|
||||
* Fixed fused games not working.
|
||||
* Fixed ParticleSystem:setSize ignoring the variation argument.
|
||||
|
||||
@@ -189,15 +189,20 @@ namespace sdl
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool Joystick::isDown(int index, int button)
|
||||
bool Joystick::isDown(int index, int * buttonlist)
|
||||
{
|
||||
if(!verifyJoystick(index))
|
||||
return false;
|
||||
|
||||
int num = getNumButtons(index);
|
||||
|
||||
for (int button = *buttonlist; button != -1; button = *(++buttonlist))
|
||||
{
|
||||
if (button < num && SDL_JoystickGetButton(joysticks[index], button) == 1)
|
||||
return true;
|
||||
}
|
||||
|
||||
if(button >= getNumButtons(index))
|
||||
return false;
|
||||
|
||||
return (SDL_JoystickGetButton(joysticks[index], button) == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
Joystick::Hat Joystick::getHat(int index, int hat)
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace sdl
|
||||
float getAxis(int index, int axis);
|
||||
int getAxes(lua_State * L);
|
||||
int getBall(lua_State * L);
|
||||
bool isDown(int index, int button);
|
||||
bool isDown(int index, int * buttonlist);
|
||||
Hat getHat(int index, int hat);
|
||||
void close(int index);
|
||||
|
||||
@@ -74,4 +74,4 @@ namespace sdl
|
||||
} // joystick
|
||||
} // love
|
||||
|
||||
#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H
|
||||
#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H
|
||||
|
||||
@@ -104,8 +104,18 @@ namespace sdl
|
||||
int w_isDown(lua_State * L)
|
||||
{
|
||||
int index = luaL_checkint(L, 1);
|
||||
int button = luaL_checkint(L, 2);
|
||||
luax_pushboolean(L, instance->isDown(index, button));
|
||||
unsigned int num = lua_gettop(L);
|
||||
int * buttonlist = new int[num];
|
||||
unsigned int counter = 0;
|
||||
|
||||
for (unsigned int i = 1; i < num; i++)
|
||||
{
|
||||
buttonlist[counter++] = luaL_checknumber(L, i+1);
|
||||
}
|
||||
buttonlist[counter] = -1;
|
||||
|
||||
luax_pushboolean(L, instance->isDown(index, buttonlist));
|
||||
delete[] buttonlist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user