Skip to content

Commit 18c2f16

Browse files
TeTpaAkakwolekr
authored andcommittedMay 15, 2015
Generalize core.get/set_nametag_color into core.get/set_nametag_attributes
1 parent 5d1d7c1 commit 18c2f16

File tree

7 files changed

+36
-26
lines changed

7 files changed

+36
-26
lines changed
 

Diff for: ‎doc/lua_api.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -2491,12 +2491,17 @@ This is basically a reference to a C++ `ServerActiveObject`
24912491
* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
24922492
* in first person view
24932493
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
2494-
* `get_nametag_color()`
2495-
* returns the color of the nametag as table
2496-
* { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
2497-
* `set_nametag_color(color)`
2498-
* sets the color of the nametag
2499-
* `color`: { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
2494+
* `get_nametag_attributes()`
2495+
* returns a table with the attributes of the nametag of the player
2496+
* {
2497+
color = { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
2498+
}
2499+
* `set_nametag_attributes(attributes)`
2500+
* sets the attributes of the nametag of the player
2501+
* `attributes`:
2502+
{
2503+
color = { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
2504+
}
25002505

25012506
### `InvRef`
25022507
An `InvRef` is a reference to an inventory.

Diff for: ‎src/content_cao.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,8 @@ void GenericCAO::processMessage(const std::string &data)
17151715
int rating = readS16(is);
17161716
m_armor_groups[name] = rating;
17171717
}
1718-
} else if (cmd == GENERIC_CMD_SET_NAMETAG_COLOR) {
1718+
} else if (cmd == GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) {
1719+
u8 version = readU8(is); // forward compatibility
17191720
m_nametag_color = readARGB8(is);
17201721
if (m_textnode != NULL) {
17211722
m_textnode->setTextColor(m_nametag_color);

Diff for: ‎src/content_sao.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
814814
os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
815815
m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
816816
m_physics_override_sneak_glitch)); // 5
817-
os << serializeLongString(gob_cmd_set_nametag_color(m_nametag_color)); // 6
817+
os << serializeLongString(gob_cmd_update_nametag_attributes(m_nametag_color)); // 6
818818
}
819819
else
820820
{
@@ -971,7 +971,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
971971

972972
if (m_nametag_sent == false) {
973973
m_nametag_sent = true;
974-
std::string str = gob_cmd_set_nametag_color(m_nametag_color);
974+
std::string str = gob_cmd_update_nametag_attributes(m_nametag_color);
975975
// create message and add to list
976976
ActiveObjectMessage aom(getId(), true, str);
977977
m_messages_out.push(aom);

Diff for: ‎src/genericobject.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,13 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit
170170
return os.str();
171171
}
172172

173-
std::string gob_cmd_set_nametag_color(video::SColor color)
173+
std::string gob_cmd_update_nametag_attributes(video::SColor color)
174174
{
175175
std::ostringstream os(std::ios::binary);
176176
// command
177-
writeU8(os, GENERIC_CMD_SET_NAMETAG_COLOR);
177+
writeU8(os, GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES);
178178
// parameters
179+
writeU8(os, 1); // version for forward compatibility
179180
writeARGB8(os, color);
180181
return os.str();
181182
}

Diff for: ‎src/genericobject.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
#define GENERIC_CMD_SET_BONE_POSITION 7
3535
#define GENERIC_CMD_SET_ATTACHMENT 8
3636
#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
37-
#define GENERIC_CMD_SET_NAMETAG_COLOR 10
37+
#define GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES 10
3838

3939
#include "object_properties.h"
4040
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
7373

7474
std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation);
7575

76-
std::string gob_cmd_set_nametag_color(video::SColor color);
76+
std::string gob_cmd_update_nametag_attributes(video::SColor color);
7777

7878
#endif
7979

Diff for: ‎src/script/lua_api/l_object.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -1274,26 +1274,27 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
12741274
return 1;
12751275
}
12761276

1277-
// set_nametag_color(self, color)
1278-
int ObjectRef::l_set_nametag_color(lua_State *L)
1277+
// set_nametag_attributes(self, attributes)
1278+
int ObjectRef::l_set_nametag_attributes(lua_State *L)
12791279
{
12801280
NO_MAP_LOCK_REQUIRED;
12811281
ObjectRef *ref = checkobject(L, 1);
12821282
PlayerSAO *playersao = getplayersao(ref);
12831283
if (playersao == NULL)
12841284
return 0;
12851285

1286-
video::SColor color(255,255,255,255);
1287-
if (!lua_isnil(L, 2))
1288-
color = readARGB8(L, 2);
1286+
video::SColor color = playersao->getNametagColor();
1287+
lua_getfield(L, 2, "color");
1288+
if (!lua_isnil(L, -1))
1289+
color = readARGB8(L, -1);
12891290
playersao->setNametagColor(color);
12901291

12911292
lua_pushboolean(L, true);
12921293
return 1;
12931294
}
12941295

1295-
// get_nametag_color(self)
1296-
int ObjectRef::l_get_nametag_color(lua_State *L)
1296+
// get_nametag_attributes(self)
1297+
int ObjectRef::l_get_nametag_attributes(lua_State *L)
12971298
{
12981299
NO_MAP_LOCK_REQUIRED;
12991300
ObjectRef *ref = checkobject(L, 1);
@@ -1303,6 +1304,7 @@ int ObjectRef::l_get_nametag_color(lua_State *L)
13031304

13041305
video::SColor color = playersao->getNametagColor();
13051306

1307+
lua_newtable(L);
13061308
lua_newtable(L);
13071309
lua_pushnumber(L, color.getAlpha());
13081310
lua_setfield(L, -2, "a");
@@ -1312,6 +1314,7 @@ int ObjectRef::l_get_nametag_color(lua_State *L)
13121314
lua_setfield(L, -2, "g");
13131315
lua_pushnumber(L, color.getBlue());
13141316
lua_setfield(L, -2, "b");
1317+
lua_setfield(L, -2, "color");
13151318

13161319
return 1;
13171320
}
@@ -1438,7 +1441,7 @@ const luaL_reg ObjectRef::methods[] = {
14381441
luamethod(ObjectRef, override_day_night_ratio),
14391442
luamethod(ObjectRef, set_local_animation),
14401443
luamethod(ObjectRef, set_eye_offset),
1441-
luamethod(ObjectRef, set_nametag_color),
1442-
luamethod(ObjectRef, get_nametag_color),
1444+
luamethod(ObjectRef, set_nametag_attributes),
1445+
luamethod(ObjectRef, get_nametag_attributes),
14431446
{0,0}
14441447
};

Diff for: ‎src/script/lua_api/l_object.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ class ObjectRef : public ModApiBase {
240240
// set_eye_offset(self, v3f first pv, v3f third pv)
241241
static int l_set_eye_offset(lua_State *L);
242242

243-
// set_nametag_color(self, color)
244-
static int l_set_nametag_color(lua_State *L);
243+
// set_nametag_attributes(self, attributes)
244+
static int l_set_nametag_attributes(lua_State *L);
245245

246-
// get_nametag_color(self)
247-
static int l_get_nametag_color(lua_State *L);
246+
// get_nametag_attributes(self)
247+
static int l_get_nametag_attributes(lua_State *L);
248248

249249
public:
250250
ObjectRef(ServerActiveObject *object);

0 commit comments

Comments
 (0)
Please sign in to comment.