aboutsummaryrefslogtreecommitdiffstats
path: root/include/inventory.hpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-01-19 16:20:13 -0500
committerClyne Sullivan <tullivan99@gmail.com>2017-01-19 16:20:13 -0500
commit59edd60ebec61bf24dd27063f85bcd049fd0af13 (patch)
tree902bb77c940134d20e35dfcb556b8e755bc373ef /include/inventory.hpp
parent36ed75a7749b81fab69f66b9ef8bbf0d18489f73 (diff)
killed common, more inventory, other random stuff
Diffstat (limited to 'include/inventory.hpp')
-rw-r--r--include/inventory.hpp75
1 files changed, 61 insertions, 14 deletions
diff --git a/include/inventory.hpp b/include/inventory.hpp
index 44ed148..2e261ae 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -1,21 +1,41 @@
+/**
+ * @file inventory.hpp
+ * @brief Provides an inventory for the player.
+ */
#ifndef INVENTORY_HPP_
#define INVENTORY_HPP_
+#include <GL/glew.h>
+#include <SDL2/SDL_opengl.h>
+
+#include <string>
+#include <vector>
+
#include <entityx/entityx.h>
+#include <tinyxml2.h>
+using namespace tinyxml2;
-#include <components.hpp>
#include <events.hpp>
+#include <texture.hpp>
+/**
+ * @struct Item
+ * Contains the information neccessary for an item.
+ */
struct Item {
- std::string name;
- std::string type;
- int value;
- int stackSize;
- Texture sprite;
+ std::string name; /**< The name of the item */
+ std::string type; /**< The type of the item */
+ int value; /**< The value/worth of the item */
+ int stackSize; /**< The stack size of the item */
+ Texture sprite; /**< The texture for the item (in inventory) */
Item(void)
: value(0), stackSize(1) {}
+ /**
+ * Constructs an item from XML.
+ * @param the xml element (<item />)
+ */
Item(XMLElement *e) {
name = e->StrAttribute("name");
type = e->StrAttribute("type");
@@ -29,35 +49,62 @@ struct Item {
}
};
+/**
+ * @struct InventoryEntry
+ * Describes a slot in the player's inventory.
+ */
struct InventoryEntry {
- Item* item;
- int count;
- vec2 loc;
+ Item* item; /**< Pointer to info on what item this slot contains */
+ int count; /**< The quantity of this item stored here */
+
+ vec2 loc; /**< Used by render, to determine slot location on screen */
InventoryEntry(void)
: item(nullptr), count(0) {}
};
+/**
+ * @class InventorySystem
+ * Handles the player's inventory system.
+ */
class InventorySystem : public entityx::System<InventorySystem>, public entityx::Receiver<InventorySystem> {
private:
+ /**
+ * A vector for the player's inventory slots.
+ */
std::vector<InventoryEntry> items;
+ void loadItems(void);
+
public:
- InventorySystem(int size = 4) {
+ InventorySystem(int size = 20) {
items.resize(size);
loadItems();
}
void configure(entityx::EventManager &ev);
-
- void loadItems(void);
-
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
-
void receive(const KeyDownEvent &kde);
+ void receive(const MouseClickEvent &mce);
+
void render(void);
+ /**
+ * Adds 'count' 'name's to the inventory.
+ * @param name the name of the item
+ * @param count the quantity of the item to give
+ */
void add(const std::string& name, int count);
+
+ /**
+ * Takes 'count' 'name's from the inventory.
+ * If the inventory does not contain enough of the item, no items are taken
+ * and false is returned.
+ * @param name the name of the item
+ * @param count the quantity of the item to take
+ * @return true if the operation could be completed
+ */
+ bool take(const std::string& name, int count);
};
#endif // INVENTORY_HPP_