summaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2021-02-17 19:51:28 +0000
committerGitHub <noreply@github.com>2021-02-17 19:51:28 +0000
commitf85e9ab9254e2ae4ac13170f9edea00fb8d931a2 (patch)
tree43fa19520c7f744f798de0ed8bcbb8e01c82e327 /src/script/common
parenta8f6befd398cb8f962f3bb1fab092d6355bfe015 (diff)
downloadminetest-f85e9ab9254e2ae4ac13170f9edea00fb8d931a2.tar.gz
minetest-f85e9ab9254e2ae4ac13170f9edea00fb8d931a2.tar.bz2
minetest-f85e9ab9254e2ae4ac13170f9edea00fb8d931a2.zip
Add nametag background setting and object property (#10937)
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_content.cpp18
-rw-r--r--src/script/common/helper.cpp24
-rw-r--r--src/script/common/helper.h3
3 files changed, 36 insertions, 9 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 2f9fbd74b..6995f6b61 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -312,6 +312,17 @@ void read_object_properties(lua_State *L, int index,
prop->nametag_color = color;
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "nametag_bgcolor");
+ if (!lua_isnil(L, -1)) {
+ if (lua_toboolean(L, -1)) {
+ video::SColor color;
+ if (read_color(L, -1, &color))
+ prop->nametag_bgcolor = color;
+ } else {
+ prop->nametag_bgcolor = nullopt;
+ }
+ }
+ lua_pop(L, 1);
lua_getfield(L, -1, "automatic_face_movement_max_rotation_per_sec");
if (lua_isnumber(L, -1)) {
@@ -403,6 +414,13 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_setfield(L, -2, "nametag");
push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "nametag_color");
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "nametag_bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "nametag_bgcolor");
+ }
lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec);
lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec");
lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());
diff --git a/src/script/common/helper.cpp b/src/script/common/helper.cpp
index 488144790..fbf24e1b7 100644
--- a/src/script/common/helper.cpp
+++ b/src/script/common/helper.cpp
@@ -50,22 +50,26 @@ bool LuaHelper::isNaN(lua_State *L, int idx)
/*
* Read template functions
*/
-template <> bool LuaHelper::readParam(lua_State *L, int index)
+template <>
+bool LuaHelper::readParam(lua_State *L, int index)
{
return lua_toboolean(L, index) != 0;
}
-template <> s16 LuaHelper::readParam(lua_State *L, int index)
+template <>
+s16 LuaHelper::readParam(lua_State *L, int index)
{
return lua_tonumber(L, index);
}
-template <> int LuaHelper::readParam(lua_State *L, int index)
+template <>
+int LuaHelper::readParam(lua_State *L, int index)
{
return luaL_checkint(L, index);
}
-template <> float LuaHelper::readParam(lua_State *L, int index)
+template <>
+float LuaHelper::readParam(lua_State *L, int index)
{
if (isNaN(L, index))
throw LuaError("NaN value is not allowed.");
@@ -73,7 +77,8 @@ template <> float LuaHelper::readParam(lua_State *L, int index)
return (float)luaL_checknumber(L, index);
}
-template <> v2s16 LuaHelper::readParam(lua_State *L, int index)
+template <>
+v2s16 LuaHelper::readParam(lua_State *L, int index)
{
v2s16 p;
CHECK_POS_TAB(index);
@@ -88,7 +93,8 @@ template <> v2s16 LuaHelper::readParam(lua_State *L, int index)
return p;
}
-template <> v2f LuaHelper::readParam(lua_State *L, int index)
+template <>
+v2f LuaHelper::readParam(lua_State *L, int index)
{
v2f p;
CHECK_POS_TAB(index);
@@ -103,7 +109,8 @@ template <> v2f LuaHelper::readParam(lua_State *L, int index)
return p;
}
-template <> v3f LuaHelper::readParam(lua_State *L, int index)
+template <>
+v3f LuaHelper::readParam(lua_State *L, int index)
{
v3f p;
CHECK_POS_TAB(index);
@@ -122,7 +129,8 @@ template <> v3f LuaHelper::readParam(lua_State *L, int index)
return p;
}
-template <> std::string LuaHelper::readParam(lua_State *L, int index)
+template <>
+std::string LuaHelper::readParam(lua_State *L, int index)
{
size_t length;
std::string result;
diff --git a/src/script/common/helper.h b/src/script/common/helper.h
index 7a794dc9b..6491e73cf 100644
--- a/src/script/common/helper.h
+++ b/src/script/common/helper.h
@@ -38,7 +38,8 @@ protected:
* @param index Lua Index to read
* @return read value from Lua
*/
- template <typename T> static T readParam(lua_State *L, int index);
+ template <typename T>
+ static T readParam(lua_State *L, int index);
/**
* Read a value using a template type T from Lua State L and index