Generalize core.get/set_nametag_color into core.get/set_nametag_attributes
authorTeTpaAka <TeTpaAka@users.noreply.github.com>
Fri, 15 May 2015 19:46:56 +0000 (21:46 +0200)
committerkwolekr <kwolekr@minetest.net>
Fri, 15 May 2015 20:21:01 +0000 (16:21 -0400)
doc/lua_api.txt
src/content_cao.cpp
src/content_sao.cpp
src/genericobject.cpp
src/genericobject.h
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h

index 8ade48b7b2f9519e9269e2bbd03a97163d3dde0a..0cc83bf69a2853127b725d67cee20b7d14bf0a84 100644 (file)
@@ -2491,12 +2491,17 @@ This is basically a reference to a C++ `ServerActiveObject`
 * `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
     * in first person view
     * in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
-* `get_nametag_color()`
-    * returns the color of the nametag as table
-    * { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
-* `set_nametag_color(color)`
-    * sets the color of the nametag
-    * `color`: { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
+* `get_nametag_attributes()`
+    * returns a table with the attributes of the nametag of the player
+    * {
+        color = { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
+      }
+* `set_nametag_attributes(attributes)`
+    * sets the attributes of the nametag of the player
+    * `attributes`:
+      {
+        color = { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
+      }
 
 ### `InvRef`
 An `InvRef` is a reference to an inventory.
index 5bf4d8e9ccd3e905beb7b4a1d4d8218d749e0732..fe560a41ad142dadccd0820443e47da21cfd41c7 100644 (file)
@@ -1715,7 +1715,8 @@ void GenericCAO::processMessage(const std::string &data)
                        int rating = readS16(is);
                        m_armor_groups[name] = rating;
                }
-       } else if (cmd == GENERIC_CMD_SET_NAMETAG_COLOR) {
+       } else if (cmd == GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) {
+               u8 version = readU8(is); // forward compatibility
                m_nametag_color = readARGB8(is);
                if (m_textnode != NULL) {
                        m_textnode->setTextColor(m_nametag_color);
index c7f4b60c7e3da8e4ff0d2f66f3c4e4ee979603a3..1f7323c9c8c73ae281e4f832f0322cdf2eec389d 100644 (file)
@@ -814,7 +814,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
                os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
                                m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
                                m_physics_override_sneak_glitch)); // 5
-               os << serializeLongString(gob_cmd_set_nametag_color(m_nametag_color)); // 6
+               os << serializeLongString(gob_cmd_update_nametag_attributes(m_nametag_color)); // 6
        }
        else
        {
@@ -971,7 +971,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
 
        if (m_nametag_sent == false) {
                m_nametag_sent = true;
-               std::string str = gob_cmd_set_nametag_color(m_nametag_color);
+               std::string str = gob_cmd_update_nametag_attributes(m_nametag_color);
                // create message and add to list
                ActiveObjectMessage aom(getId(), true, str);
                m_messages_out.push(aom);
index 1f4f59e92b4ad17b1843752fef03c9a80223c362..78dc7fa9172d3f506d077390f60313e6fb5a352c 100644 (file)
@@ -170,12 +170,13 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit
        return os.str();
 }
 
-std::string gob_cmd_set_nametag_color(video::SColor color)
+std::string gob_cmd_update_nametag_attributes(video::SColor color)
 {
        std::ostringstream os(std::ios::binary);
        // command
-       writeU8(os, GENERIC_CMD_SET_NAMETAG_COLOR);
+       writeU8(os, GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES);
        // parameters
+       writeU8(os, 1); // version for forward compatibility
        writeARGB8(os, color);
        return os.str();
 }
index 854950d27e5dd534050c6cf9a3b41b5fff24f6d7..2233e4ea04c059858d88ed9c1ad42c682c9e2dc3 100644 (file)
@@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define GENERIC_CMD_SET_BONE_POSITION 7
 #define GENERIC_CMD_SET_ATTACHMENT 8
 #define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
-#define GENERIC_CMD_SET_NAMETAG_COLOR 10
+#define GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES 10
 
 #include "object_properties.h"
 std::string gob_cmd_set_properties(const ObjectProperties &prop);
@@ -73,7 +73,7 @@ std::string gob_cmd_update_bone_position(std::string bone, v3f position, v3f rot
 
 std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation);
 
-std::string gob_cmd_set_nametag_color(video::SColor color);
+std::string gob_cmd_update_nametag_attributes(video::SColor color);
 
 #endif
 
index c639a48343dc5b0b03ec05b16a661a0e8c4e368f..845aab732c2ddc8cfd16658ef1c411887fcd844e 100644 (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}
 };
index 1f2931f2984bef63d088f34ccd45ef8432876c6d..af3ed5ef06da2e1b9e1233d558ab202e40d46aef 100644 (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);