summaryrefslogtreecommitdiff
path: root/src/inventory.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2010-12-22 11:29:06 +0200
committerPerttu Ahola <celeron55@gmail.com>2010-12-22 11:29:06 +0200
commit2e41a5e304d9c35ece851b8a65482bca8784b582 (patch)
treeb8508e3d2f752367a74970385fa4ec9244eb04b0 /src/inventory.h
parent4ec61b0ccdedecf54cd697d0b1cfa16aaf92bf82 (diff)
downloadminetest-2e41a5e304d9c35ece851b8a65482bca8784b582.tar.gz
minetest-2e41a5e304d9c35ece851b8a65482bca8784b582.tar.bz2
minetest-2e41a5e304d9c35ece851b8a65482bca8784b582.zip
just savin'
Diffstat (limited to 'src/inventory.h')
-rw-r--r--src/inventory.h45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/inventory.h b/src/inventory.h
index c18aa5dce..d37761cfe 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -196,18 +196,21 @@ private:
std::string m_inventorystring;
};
-class Inventory
+class InventoryList
{
public:
- Inventory(u32 size);
- ~Inventory();
+ InventoryList(std::string name, u32 size);
+ ~InventoryList();
void clearItems();
void serialize(std::ostream &os);
void deSerialize(std::istream &is);
- Inventory & operator = (Inventory &other);
+ InventoryList(const InventoryList &other);
+ InventoryList & operator = (const InventoryList &other);
+ std::string getName();
u32 getSize();
+ // Count used slots
u32 getUsedSlots();
InventoryItem * getItem(u32 i);
@@ -222,6 +225,40 @@ public:
private:
core::array<InventoryItem*> m_items;
u32 m_size;
+ std::string m_name;
+};
+
+class Inventory
+{
+public:
+ ~Inventory();
+
+ void clear();
+
+ Inventory();
+ Inventory(const Inventory &other);
+ Inventory & operator = (const Inventory &other);
+
+ void serialize(std::ostream &os);
+ void deSerialize(std::istream &is);
+
+ InventoryList * addList(const std::string &name, u32 size);
+ InventoryList * getList(const std::string &name);
+ bool deleteList(const std::string &name);
+ // A shorthand for adding items
+ bool addItem(const std::string &listname, InventoryItem *newitem)
+ {
+ InventoryList *list = getList(listname);
+ if(list == NULL)
+ return false;
+ return list->addItem(newitem);
+ }
+
+private:
+ // -1 if not found
+ s32 getListIndex(const std::string &name);
+
+ core::array<InventoryList*> m_lists;
};
#endif