Browse Source

Added love.system.vibrate(time), which causes the phone to vibrate on Android. love.system.getOS() now returns "Android" on Android. Implemented love.system.openURL.

Martin Felis 10 years ago
parent
commit
2ab69094e1

+ 2 - 1
changes.txt

@@ -3,7 +3,8 @@ LOVE 0.10.0 []
 
 Released: N/A
 
-  * Added a (work-in-progress) iOS port.
+  * Added an iOS port.
+  * Added an Android port.
   * Added the flag t.accelerometerjoystick to love.conf. Disables accelerometer-as-joystick functionality on mobile devices when false.
   * Added the flag t.gammacorrect to love.conf (replaces t.window.srgb.) Enabling it globally enables gamma-correct rendering, when supported.
   * Added love.touch module. Note that it has important differences from the touch implementation in the LÖVE 0.9 Android and iOS ports.

+ 2 - 0
src/modules/love/love.cpp

@@ -306,6 +306,8 @@ int luaopen_love(lua_State *L)
 	lua_pushstring(L, "OS X");
 #elif defined(LOVE_IOS)
 	lua_pushstring(L, "iOS");
+#elif defined(LOVE_ANDROID)
+	lua_pushstring(L, "Android");
 #elif defined(LOVE_LINUX)
 	lua_pushstring(L, "Linux");
 #else

+ 17 - 0
src/modules/system/System.cpp

@@ -26,6 +26,8 @@
 #include <CoreServices/CoreServices.h>
 #elif defined(LOVE_IOS)
 #include "common/iOS.h"
+#elif defined(LOVE_ANDROID)
+#include "common/android.h"
 #elif defined(LOVE_LINUX)
 #include <spawn.h>
 //#include <stdlib.h>
@@ -66,6 +68,8 @@ std::string System::getOS() const
 	return "iOS";
 #elif defined(LOVE_WINDOWS)
 	return "Windows";
+#elif defined(LOVE_ANDROID)
+	return "Android";
 #elif defined(LOVE_LINUX)
 	return "Linux";
 #else
@@ -98,6 +102,10 @@ bool System::openURL(const std::string &url) const
 
 	return love::ios::openURL(url);
 
+#elif defined(LOVE_ANDROID)
+
+	return love::android::openURL(url);
+
 #elif defined(LOVE_LINUX)
 
 	pid_t pid;
@@ -134,6 +142,15 @@ bool System::openURL(const std::string &url) const
 #endif
 }
 
+void System::vibrate(double seconds) const
+{
+#ifdef LOVE_ANDROID
+	love::android::vibrate(seconds);
+#else
+	LOVE_UNUSED(seconds);
+#endif
+}
+
 bool System::getConstant(const char *in, System::PowerState &out)
 {
 	return powerStates.find(in, out);

+ 7 - 0
src/modules/system/System.h

@@ -99,6 +99,13 @@ public:
 	 **/
 	virtual bool openURL(const std::string &url) const;
 
+	/**
+	 * Vibrates for the specified amount of seconds.
+	 *
+	 * @param number of seconds to vibrate.
+	 */
+	virtual void vibrate(double seconds) const;
+
 	static bool getConstant(const char *in, PowerState &out);
 	static bool getConstant(PowerState in, const char *&out);
 

+ 8 - 0
src/modules/system/wrap_System.cpp

@@ -86,6 +86,13 @@ int w_openURL(lua_State *L)
 	return 1;
 }
 
+int w_vibrate(lua_State *L)
+{
+	double seconds = luaL_checknumber(L, 1);
+	instance()->vibrate(seconds);
+	return 0;
+}
+
 static const luaL_Reg functions[] =
 {
 	{ "getOS", w_getOS },
@@ -94,6 +101,7 @@ static const luaL_Reg functions[] =
 	{ "getClipboardText", w_getClipboardText },
 	{ "getPowerInfo", w_getPowerInfo },
 	{ "openURL", w_openURL },
+	{ "vibrate", w_vibrate },
 	{ 0, 0 }
 };
 

+ 1 - 0
src/modules/system/wrap_System.h

@@ -36,6 +36,7 @@ int w_setClipboardText(lua_State *L);
 int w_getClipboardText(lua_State *L);
 int w_getPowerInfo(lua_State *L);
 int w_openURL(lua_State *L);
+int w_vibrate(lua_State *L);
 extern "C" LOVE_EXPORT int luaopen_love_system(lua_State *L);
 
 } // system