summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-05-02 23:52:50 +0300
committersapier <Sapier at GMX dot net>2014-02-01 18:34:26 +0100
commit86a6cca3cf641fc2c88184ad26d2be3d7e7460f7 (patch)
tree25406b5df8244667ae3c494eaf3f945be1d0ae2b /src/script/lua_api/l_object.cpp
parente258675eabc874d31bc9c6cf49e4bbc1f7f3f417 (diff)
downloadminetest-86a6cca3cf641fc2c88184ad26d2be3d7e7460f7.tar.gz
minetest-86a6cca3cf641fc2c88184ad26d2be3d7e7460f7.tar.bz2
minetest-86a6cca3cf641fc2c88184ad26d2be3d7e7460f7.zip
Add player:set_sky() with simple skybox support
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 6c6415a09..86e5a71cd 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -1090,6 +1090,45 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
return 1;
}
+// set_sky(self, bgcolor, type, list)
+int ObjectRef::l_set_sky(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if (player == NULL)
+ return 0;
+
+ video::SColor bgcolor(255,255,255,255);
+ if (!lua_isnil(L, 2))
+ bgcolor = readARGB8(L, 2);
+
+ std::string type = luaL_checkstring(L, 3);
+
+ std::vector<std::string> params;
+ if (lua_istable(L, 4)) {
+ int table = lua_gettop(L);
+ lua_pushnil(L);
+ while (lua_next(L, table) != 0) {
+ // key at index -2 and value at index -1
+ if (lua_isstring(L, -1))
+ params.push_back(lua_tostring(L, -1));
+ else
+ params.push_back("");
+ // removes value, keeps key for next iteration
+ lua_pop(L, 1);
+ }
+ }
+
+ if (type == "skybox" && params.size() != 6)
+ throw LuaError(L, "skybox expects 6 textures");
+
+ if (!getServer(L)->setSky(player, bgcolor, type, params))
+ return 0;
+
+ lua_pushboolean(L, true);
+ return 1;
+}
+
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{
@@ -1207,5 +1246,6 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, hud_set_hotbar_itemcount),
luamethod(ObjectRef, hud_set_hotbar_image),
luamethod(ObjectRef, hud_set_hotbar_selected_image),
+ luamethod(ObjectRef, set_sky),
{0,0}
};