-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.hpp
58 lines (41 loc) · 1.39 KB
/
Inventory.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef INVENTORY_HPP
#define INVENTORY_HPP
#include "Block.hpp"
#include "Vec2.hpp"
#include "BitmapFont.hpp"
#include <SFML/Graphics.hpp>
#include <vector>
class InventoryStack {
public:
size_t count, size;
blockid type;
InventoryStack(size_t count, blockid type, size_t maxSize = 64);
InventoryStack();
bool operator==(const InventoryStack &);
/* Returns if this stack is free (no elements or blockid == AIR) */
bool isFree();
/* Returns how many elements can be added to the stack before it's full */
size_t spaceLeft();
/* Add n elements to the stack, returns count of elements that could not be added because the stack is too small */
size_t add(size_t elements = 1);
/* Return current blocktype, if no elements are left return BLOCK_AIR */
blockid get();
/* Acts like InventoryStack::get() but shrinks the stack by one every call */
blockid take();
void render(sf::RenderTarget &, BitmapFont &, Vec2);
};
class Inventory {
std::vector<InventoryStack> content;
public:
Inventory(size_t);
/* Returns max. number of available stacks */
size_t getSize();
/* Returns true if at least one InventoryStack does not hold any items */
bool hasSpace();
bool hasSpaceFor(blockid);
/* Returns the InventoryStack at index */
InventoryStack &at(size_t);
/* Adds InventoryStack to next free space, returns false if no free InventoryStack was found */
bool add(InventoryStack);
};
#endif