Alex Szpakowski avatar Alex Szpakowski committed 582f400

Fixed ParticleSystem:setAreaSpread("none") to not require x/y arguments (resolves issue #738)

Comments (0)

Files changed (3)

src/modules/graphics/opengl/wrap_Graphics.cpp

 	Image *image = luax_checkimage(L, 1);
 	lua_Number size = luaL_optnumber(L, 2, 1000);
 	ParticleSystem *t = 0;
-	if (size < 1.0 || size > LOVE_UINT32_MAX)
+	if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES)
 		return luaL_error(L, "Invalid ParticleSystem size");	
 
 	EXCEPT_GUARD(t = instance->newParticleSystem(image, size);)

src/modules/graphics/opengl/wrap_ParticleSystem.cpp

 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
 
-	ParticleSystem::AreaSpreadDistribution distribution;
-	const char *str = luaL_checkstring(L, 2);
-	if (!ParticleSystem::getConstant(str, distribution))
-		return luaL_error(L, "Invalid distribution: '%s'", str);
+	ParticleSystem::AreaSpreadDistribution distribution = ParticleSystem::DISTRIBUTION_NONE;
+	float x = 0.f, y = 0.f;
 
-	float x = (float)luaL_checknumber(L, 3);
-	float y = (float)luaL_checknumber(L, 4);
-	if (x < 0.0f || y < 0.0f)
-		return luaL_error(L, "Invalid area spread parameters (must be >= 0)");
+	const char *str = lua_isnoneornil(L, 2) ? 0 : luaL_checkstring(L, 2);
+	if (str && !ParticleSystem::getConstant(str, distribution))
+		return luaL_error(L, "Invalid particle distribution: %s", str);
+
+	if (distribution != ParticleSystem::DISTRIBUTION_NONE)
+	{
+		x = (float) luaL_checknumber(L, 3);
+		y = (float) luaL_checknumber(L, 4);
+		if (x < 0.0f || y < 0.0f)
+			return luaL_error(L, "Invalid area spread parameters (must be >= 0)");
+	}
 
 	t->setAreaSpread(distribution, x, y);
 	return 0;

src/modules/window/wrap_Window.cpp

 	bool fullscreen = luax_toboolean(L, 1);
 	Window::FullscreenType fstype = Window::FULLSCREEN_TYPE_MAX_ENUM;
 
-	const char *typestr = lua_isnoneornil(L, 2) ? 0 : lua_tostring(L, 2);
+	const char *typestr = lua_isnoneornil(L, 2) ? 0 : luaL_checkstring(L, 2);
 	if (typestr && !Window::getConstant(typestr, fstype))
 		return luaL_error(L, "Invalid fullscreen type: %s", typestr);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.