summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorIlya Zhuravlev <zhuravlevilya@ya.ru>2012-08-20 01:29:56 +0400
committerPerttu Ahola <celeron55@gmail.com>2012-09-01 10:01:41 +0300
commit6a16075912d016926ee0361fb85f9979c119be52 (patch)
tree9f0b589efac5266eb51db71643e174187f83cf3e /src/inventory.cpp
parent43ebec2be1949aa5eac127df7cb902d37e4e461b (diff)
downloadminetest-6a16075912d016926ee0361fb85f9979c119be52.tar.gz
minetest-6a16075912d016926ee0361fb85f9979c119be52.tar.bz2
minetest-6a16075912d016926ee0361fb85f9979c119be52.zip
Add InventoryList width property & allow custom crafting grids.
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 0a0a29cd5..fda11e40f 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -431,6 +431,7 @@ InventoryList::InventoryList(std::string name, u32 size, IItemDefManager *itemde
{
m_name = name;
m_size = size;
+ m_width = 0;
m_itemdef = itemdef;
clearItems();
//m_dirty = false;
@@ -459,6 +460,11 @@ void InventoryList::setSize(u32 newsize)
m_size = newsize;
}
+void InventoryList::setWidth(u32 newwidth)
+{
+ m_width = newwidth;
+}
+
void InventoryList::setName(const std::string &name)
{
m_name = name;
@@ -468,6 +474,8 @@ void InventoryList::serialize(std::ostream &os) const
{
//os.imbue(std::locale("C"));
+ os<<"Width "<<m_width<<"\n";
+
for(u32 i=0; i<m_items.size(); i++)
{
const ItemStack &item = m_items[i];
@@ -492,6 +500,7 @@ void InventoryList::deSerialize(std::istream &is)
clearItems();
u32 item_i = 0;
+ m_width = 0;
for(;;)
{
@@ -513,6 +522,12 @@ void InventoryList::deSerialize(std::istream &is)
{
break;
}
+ else if(name == "Width")
+ {
+ iss >> m_width;
+ if (iss.fail())
+ throw SerializationError("incorrect width property");
+ }
else if(name == "Item")
{
if(item_i > getSize() - 1)
@@ -543,6 +558,7 @@ InventoryList & InventoryList::operator = (const InventoryList &other)
{
m_items = other.m_items;
m_size = other.m_size;
+ m_width = other.m_width;
m_name = other.m_name;
m_itemdef = other.m_itemdef;
//setDirty(true);
@@ -560,6 +576,11 @@ u32 InventoryList::getSize() const
return m_items.size();
}
+u32 InventoryList::getWidth() const
+{
+ return m_width;
+}
+
u32 InventoryList::getUsedSlots() const
{
u32 num = 0;