aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/inventory.cpp14
-rw-r--r--src/inventory.h1
-rw-r--r--src/itemdef.cpp9
-rw-r--r--src/itemdef.h1
-rw-r--r--src/script/common/c_content.cpp3
-rw-r--r--src/script/lua_api/l_item.cpp11
-rw-r--r--src/script/lua_api/l_item.h3
7 files changed, 40 insertions, 2 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index cf72cb005..1ef9b13cd 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -258,6 +258,20 @@ std::string ItemStack::getDescription(IItemDefManager *itemdef) const
return desc.empty() ? name : desc;
}
+std::string ItemStack::getShortDescription(IItemDefManager *itemdef) const
+{
+ std::string desc = metadata.getString("short_description");
+ if (desc.empty())
+ desc = getDefinition(itemdef).short_description;
+ if (!desc.empty())
+ return desc;
+ // no short_description because of old server version or modified builtin
+ // return first line of description
+ std::stringstream sstr(getDescription(itemdef));
+ std::getline(sstr, desc, '\n');
+ return desc;
+}
+
ItemStack ItemStack::addItem(ItemStack newitem, IItemDefManager *itemdef)
{
diff --git a/src/inventory.h b/src/inventory.h
index 67a7859ed..f36bc57cf 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -49,6 +49,7 @@ struct ItemStack
std::string getItemString(bool include_meta = true) const;
// Returns the tooltip
std::string getDescription(IItemDefManager *itemdef) const;
+ std::string getShortDescription(IItemDefManager *itemdef) const;
/*
Quantity methods
diff --git a/src/itemdef.cpp b/src/itemdef.cpp
index df20bdf15..5fb1e4c47 100644
--- a/src/itemdef.cpp
+++ b/src/itemdef.cpp
@@ -62,6 +62,7 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
type = def.type;
name = def.name;
description = def.description;
+ short_description = def.short_description;
inventory_image = def.inventory_image;
inventory_overlay = def.inventory_overlay;
wield_image = def.wield_image;
@@ -102,6 +103,7 @@ void ItemDefinition::reset()
type = ITEM_NONE;
name = "";
description = "";
+ short_description = "";
inventory_image = "";
inventory_overlay = "";
wield_image = "";
@@ -162,6 +164,8 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
writeARGB8(os, color);
os << serializeString16(inventory_overlay);
os << serializeString16(wield_overlay);
+
+ os << serializeString16(short_description);
}
void ItemDefinition::deSerialize(std::istream &is)
@@ -213,8 +217,9 @@ void ItemDefinition::deSerialize(std::istream &is)
// If you add anything here, insert it primarily inside the try-catch
// block to not need to increase the version.
- //try {
- //} catch(SerializationError &e) {};
+ try {
+ short_description = deSerializeString16(is);
+ } catch(SerializationError &e) {};
}
diff --git a/src/itemdef.h b/src/itemdef.h
index f47e6cbe7..ebf0d3527 100644
--- a/src/itemdef.h
+++ b/src/itemdef.h
@@ -56,6 +56,7 @@ struct ItemDefinition
ItemType type;
std::string name; // "" = hand
std::string description; // Shown in tooltip.
+ std::string short_description;
/*
Visual properties
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 774b6a326..147f6e3ed 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -56,6 +56,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);
@@ -142,6 +143,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());
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp
index d67cab76f..2d1124a4d 100644
--- a/src/script/lua_api/l_item.cpp
+++ b/src/script/lua_api/l_item.cpp
@@ -193,6 +193,16 @@ int LuaItemStack::l_get_description(lua_State *L)
return 1;
}
+// get_short_description(self)
+int LuaItemStack::l_get_short_description(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ LuaItemStack *o = checkobject(L, 1);
+ std::string desc = o->m_stack.getShortDescription(getGameDef(L)->idef());
+ lua_pushstring(L, desc.c_str());
+ return 1;
+}
+
// clear(self) -> true
int LuaItemStack::l_clear(lua_State *L)
{
@@ -493,6 +503,7 @@ const luaL_Reg LuaItemStack::methods[] = {
luamethod(LuaItemStack, get_metadata),
luamethod(LuaItemStack, set_metadata),
luamethod(LuaItemStack, get_description),
+ luamethod(LuaItemStack, get_short_description),
luamethod(LuaItemStack, clear),
luamethod(LuaItemStack, replace),
luamethod(LuaItemStack, to_string),
diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h
index 98744c071..16878c101 100644
--- a/src/script/lua_api/l_item.h
+++ b/src/script/lua_api/l_item.h
@@ -72,6 +72,9 @@ private:
// get_description(self)
static int l_get_description(lua_State *L);
+ // get_short_description(self)
+ static int l_get_short_description(lua_State *L);
+
// clear(self) -> true
static int l_clear(lua_State *L);