aboutsummaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-11-28 13:48:33 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-11-28 13:48:33 +0100
commiteb6aca8b4a67ef55108231e71ff29a18a29bf5ae (patch)
treef891914d25cae2cdaa24392381436a287340651e /src/script/common
parent8de51dae97aa2fe6ea02e4cf437bfe2b2a38eb06 (diff)
parentf1d72d212a0661588be27003069abf4bd8092e55 (diff)
downloaddragonfireclient-eb6aca8b4a67ef55108231e71ff29a18a29bf5ae.tar.xz
Merged Minetest
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_content.cpp16
-rw-r--r--src/script/common/c_content.h3
-rw-r--r--src/script/common/c_converter.cpp45
-rw-r--r--src/script/common/c_converter.h2
-rw-r--r--src/script/common/c_internal.cpp20
-rw-r--r--src/script/common/c_internal.h20
-rw-r--r--src/script/common/helper.cpp44
-rw-r--r--src/script/common/helper.h5
8 files changed, 73 insertions, 82 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 78c46f0e0..04f4c335c 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -57,6 +57,7 @@ void read_item_definition(lua_State* L, int index,
es_ItemType, ITEM_NONE);
getstringfield(L, index, "name", def.name);
getstringfield(L, index, "description", def.description);
+ getstringfield(L, index, "short_description", def.short_description);
getstringfield(L, index, "inventory_image", def.inventory_image);
getstringfield(L, index, "inventory_overlay", def.inventory_overlay);
getstringfield(L, index, "wield_image", def.wield_image);
@@ -143,6 +144,8 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
lua_setfield(L, -2, "name");
lua_pushstring(L, i.description.c_str());
lua_setfield(L, -2, "description");
+ lua_pushstring(L, i.short_description.c_str());
+ lua_setfield(L, -2, "short_description");
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
lua_pushstring(L, i.inventory_image.c_str());
@@ -331,6 +334,7 @@ void read_object_properties(lua_State *L, int index,
getfloatfield(L, -1, "zoom_fov", prop->zoom_fov);
getboolfield(L, -1, "use_texture_alpha", prop->use_texture_alpha);
getboolfield(L, -1, "shaded", prop->shaded);
+ getboolfield(L, -1, "show_on_minimap", prop->show_on_minimap);
getstringfield(L, -1, "damage_texture_modifier", prop->damage_texture_modifier);
}
@@ -419,6 +423,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_setfield(L, -2, "shaded");
lua_pushlstring(L, prop->damage_texture_modifier.c_str(), prop->damage_texture_modifier.size());
lua_setfield(L, -2, "damage_texture_modifier");
+ lua_pushboolean(L, prop->show_on_minimap);
+ lua_setfield(L, -2, "show_on_minimap");
}
/******************************************************************************/
@@ -491,13 +497,11 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
}
/******************************************************************************/
-ContentFeatures read_content_features(lua_State *L, int index)
+void read_content_features(lua_State *L, ContentFeatures &f, int index)
{
if(index < 0)
index = lua_gettop(L) + 1 + index;
- ContentFeatures f;
-
/* Cache existence of some callbacks */
lua_getfield(L, index, "on_construct");
if(!lua_isnil(L, -1)) f.has_on_construct = true;
@@ -800,7 +804,6 @@ ContentFeatures read_content_features(lua_State *L, int index)
getstringfield(L, index, "node_dig_prediction",
f.node_dig_prediction);
- return f;
}
void push_content_features(lua_State *L, const ContentFeatures &c)
@@ -1977,9 +1980,10 @@ void push_hud_element(lua_State *L, HudElement *elem)
HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
{
HudElementStat stat = HUD_STAT_NUMBER;
+ std::string statstr;
if (lua_isstring(L, 3)) {
int statint;
- std::string statstr = lua_tostring(L, 3);
+ statstr = lua_tostring(L, 3);
stat = string_to_enum(es_HudElementStat, statint, statstr) ?
(HudElementStat)statint : stat;
}
@@ -2007,6 +2011,8 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
break;
case HUD_STAT_ITEM:
elem->item = luaL_checknumber(L, 4);
+ if (elem->type == HUD_ELEM_WAYPOINT && statstr == "precision")
+ elem->item++;
*value = &elem->item;
break;
case HUD_STAT_DIR:
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index eeef71c36..08c74c292 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -67,7 +67,8 @@ struct collisionMoveResult;
extern struct EnumString es_TileAnimationType[];
-ContentFeatures read_content_features (lua_State *L, int index);
+void read_content_features (lua_State *L, ContentFeatures &f,
+ int index);
void push_content_features (lua_State *L,
const ContentFeatures &c);
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp
index eb6ab5331..c00401b58 100644
--- a/src/script/common/c_converter.cpp
+++ b/src/script/common/c_converter.cpp
@@ -679,48 +679,3 @@ size_t write_array_slice_float(
return elem_index - 1;
}
-
-
-size_t write_array_slice_u16(
- lua_State *L,
- int table_index,
- u16 *data,
- v3u16 data_size,
- v3u16 slice_offset,
- v3u16 slice_size)
-{
- v3u16 pmin, pmax(data_size);
-
- if (slice_offset.X > 0) {
- slice_offset.X--;
- pmin.X = slice_offset.X;
- pmax.X = MYMIN(slice_offset.X + slice_size.X, data_size.X);
- }
-
- if (slice_offset.Y > 0) {
- slice_offset.Y--;
- pmin.Y = slice_offset.Y;
- pmax.Y = MYMIN(slice_offset.Y + slice_size.Y, data_size.Y);
- }
-
- if (slice_offset.Z > 0) {
- slice_offset.Z--;
- pmin.Z = slice_offset.Z;
- pmax.Z = MYMIN(slice_offset.Z + slice_size.Z, data_size.Z);
- }
-
- const u32 ystride = data_size.X;
- const u32 zstride = data_size.X * data_size.Y;
-
- u32 elem_index = 1;
- for (u32 z = pmin.Z; z != pmax.Z; z++)
- for (u32 y = pmin.Y; y != pmax.Y; y++)
- for (u32 x = pmin.X; x != pmax.X; x++) {
- u32 i = z * zstride + y * ystride + x;
- lua_pushinteger(L, data[i]);
- lua_rawseti(L, table_index, elem_index);
- elem_index++;
- }
-
- return elem_index - 1;
-}
diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h
index a4a7079fd..6ad6f3212 100644
--- a/src/script/common/c_converter.h
+++ b/src/script/common/c_converter.h
@@ -136,5 +136,3 @@ void warn_if_field_exists(lua_State *L, int table,
size_t write_array_slice_float(lua_State *L, int table_index, float *data,
v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);
-size_t write_array_slice_u16(lua_State *L, int table_index, u16 *data,
- v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index 6df1f8b7b..ad5f836c5 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -155,24 +155,28 @@ static void script_log(lua_State *L, const std::string &message,
infostream << script_get_backtrace(L) << std::endl;
}
-void log_deprecated(lua_State *L, const std::string &message, int stack_depth)
+DeprecatedHandlingMode get_deprecated_handling_mode()
{
static thread_local bool configured = false;
- static thread_local bool do_log = false;
- static thread_local bool do_error = false;
+ static thread_local DeprecatedHandlingMode ret = DeprecatedHandlingMode::Ignore;
// Only read settings on first call
if (!configured) {
std::string value = g_settings->get("deprecated_lua_api_handling");
if (value == "log") {
- do_log = true;
+ ret = DeprecatedHandlingMode::Log;
} else if (value == "error") {
- do_log = true;
- do_error = true;
+ ret = DeprecatedHandlingMode::Error;
}
configured = true;
}
- if (do_log)
- script_log(L, message, warningstream, do_error, stack_depth);
+ return ret;
+}
+
+void log_deprecated(lua_State *L, const std::string &message, int stack_depth)
+{
+ DeprecatedHandlingMode mode = get_deprecated_handling_mode();
+ if (mode != DeprecatedHandlingMode::Ignore)
+ script_log(L, message, warningstream, mode == DeprecatedHandlingMode::Error, stack_depth);
}
diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h
index 442546332..452c2dd5e 100644
--- a/src/script/common/c_internal.h
+++ b/src/script/common/c_internal.h
@@ -114,5 +114,25 @@ void script_error(lua_State *L, int pcall_result, const char *mod, const char *f
void script_run_callbacks_f(lua_State *L, int nargs,
RunCallbacksMode mode, const char *fxn);
+enum class DeprecatedHandlingMode {
+ Ignore,
+ Log,
+ Error
+};
+
+/**
+ * Reads `deprecated_lua_api_handling` in settings, returns cached value.
+ *
+ * @return DeprecatedHandlingMode
+ */
+DeprecatedHandlingMode get_deprecated_handling_mode();
+
+/**
+ * Handles a deprecation warning based on user settings
+ *
+ * @param L Lua State
+ * @param message The deprecation method
+ * @param stack_depth How far on the stack to the first user function (ie: not builtin or core)
+ */
void log_deprecated(lua_State *L, const std::string &message,
int stack_depth=1);
diff --git a/src/script/common/helper.cpp b/src/script/common/helper.cpp
index f53a2b7e8..488144790 100644
--- a/src/script/common/helper.cpp
+++ b/src/script/common/helper.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cmath>
#include <sstream>
#include <irr_v2d.h>
+#include <irr_v3d.h>
#include "c_types.h"
#include "c_internal.h"
@@ -54,17 +55,14 @@ template <> bool LuaHelper::readParam(lua_State *L, int index)
return lua_toboolean(L, index) != 0;
}
-template <> bool LuaHelper::readParam(lua_State *L, int index, const bool &default_value)
+template <> s16 LuaHelper::readParam(lua_State *L, int index)
{
- if (lua_isnil(L, index))
- return default_value;
-
- return lua_toboolean(L, index) != 0;
+ return lua_tonumber(L, index);
}
-template <> s16 LuaHelper::readParam(lua_State *L, int index)
+template <> int LuaHelper::readParam(lua_State *L, int index)
{
- return lua_tonumber(L, index);
+ return luaL_checkint(L, index);
}
template <> float LuaHelper::readParam(lua_State *L, int index)
@@ -105,6 +103,25 @@ template <> v2f LuaHelper::readParam(lua_State *L, int index)
return p;
}
+template <> v3f LuaHelper::readParam(lua_State *L, int index)
+{
+ v3f p;
+ CHECK_POS_TAB(index);
+ lua_getfield(L, index, "x");
+ CHECK_POS_COORD("x");
+ p.X = readParam<float>(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, index, "y");
+ CHECK_POS_COORD("y");
+ p.Y = readParam<float>(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, index, "z");
+ CHECK_POS_COORD("z");
+ p.Z = readParam<float>(L, -1);
+ lua_pop(L, 1);
+ return p;
+}
+
template <> std::string LuaHelper::readParam(lua_State *L, int index)
{
size_t length;
@@ -113,16 +130,3 @@ template <> std::string LuaHelper::readParam(lua_State *L, int index)
result.assign(str, length);
return result;
}
-
-template <>
-std::string LuaHelper::readParam(
- lua_State *L, int index, const std::string &default_value)
-{
- std::string result;
- const char *str = lua_tostring(L, index);
- if (str)
- result.append(str);
- else
- result = default_value;
- return result;
-}
diff --git a/src/script/common/helper.h b/src/script/common/helper.h
index d639d6e16..7a794dc9b 100644
--- a/src/script/common/helper.h
+++ b/src/script/common/helper.h
@@ -50,5 +50,8 @@ protected:
* @return read value from Lua or default value if nil
*/
template <typename T>
- static T readParam(lua_State *L, int index, const T &default_value);
+ static inline T readParam(lua_State *L, int index, const T &default_value)
+ {
+ return lua_isnoneornil(L, index) ? default_value : readParam<T>(L, index);
+ }
};