1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Generalize core.get/set_nametag_color into core.get/set_nametag_attributes

This commit is contained in:
TeTpaAka 2015-05-15 21:46:56 +02:00 committed by kwolekr
parent 5d1d7c17ea
commit 18c2f16c13
7 changed files with 36 additions and 26 deletions

View file

@ -1274,8 +1274,8 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
return 1;
}
// set_nametag_color(self, color)
int ObjectRef::l_set_nametag_color(lua_State *L)
// set_nametag_attributes(self, attributes)
int ObjectRef::l_set_nametag_attributes(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@ -1283,17 +1283,18 @@ int ObjectRef::l_set_nametag_color(lua_State *L)
if (playersao == NULL)
return 0;
video::SColor color(255,255,255,255);
if (!lua_isnil(L, 2))
color = readARGB8(L, 2);
video::SColor color = playersao->getNametagColor();
lua_getfield(L, 2, "color");
if (!lua_isnil(L, -1))
color = readARGB8(L, -1);
playersao->setNametagColor(color);
lua_pushboolean(L, true);
return 1;
}
// get_nametag_color(self)
int ObjectRef::l_get_nametag_color(lua_State *L)
// get_nametag_attributes(self)
int ObjectRef::l_get_nametag_attributes(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
@ -1303,6 +1304,7 @@ int ObjectRef::l_get_nametag_color(lua_State *L)
video::SColor color = playersao->getNametagColor();
lua_newtable(L);
lua_newtable(L);
lua_pushnumber(L, color.getAlpha());
lua_setfield(L, -2, "a");
@ -1312,6 +1314,7 @@ int ObjectRef::l_get_nametag_color(lua_State *L)
lua_setfield(L, -2, "g");
lua_pushnumber(L, color.getBlue());
lua_setfield(L, -2, "b");
lua_setfield(L, -2, "color");
return 1;
}
@ -1438,7 +1441,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, override_day_night_ratio),
luamethod(ObjectRef, set_local_animation),
luamethod(ObjectRef, set_eye_offset),
luamethod(ObjectRef, set_nametag_color),
luamethod(ObjectRef, get_nametag_color),
luamethod(ObjectRef, set_nametag_attributes),
luamethod(ObjectRef, get_nametag_attributes),
{0,0}
};

View file

@ -240,11 +240,11 @@ private:
// set_eye_offset(self, v3f first pv, v3f third pv)
static int l_set_eye_offset(lua_State *L);
// set_nametag_color(self, color)
static int l_set_nametag_color(lua_State *L);
// set_nametag_attributes(self, attributes)
static int l_set_nametag_attributes(lua_State *L);
// get_nametag_color(self)
static int l_get_nametag_color(lua_State *L);
// get_nametag_attributes(self)
static int l_get_nametag_attributes(lua_State *L);
public:
ObjectRef(ServerActiveObject *object);