1. miriam_gsm81
  2. love

Commits

Bart van Strien  committed bae4a59

love.joystick.isDown gets multiple arguments too

  • Participants
  • Parent commits 5971f2e
  • Branches default

Comments (0)

Files changed (4)

File changes.txt

View file
 
   * 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.

File src/modules/joystick/sdl/Joystick.cpp

View file
 		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)

File src/modules/joystick/sdl/Joystick.h

View file
 		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);
 
 } // joystick
 } // love
 
-#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H
+#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H

File src/modules/joystick/sdl/wrap_Joystick.cpp

View file
 	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;
 	}