diff options
Diffstat (limited to 'src/shared/item/items.hh')
| -rw-r--r-- | src/shared/item/items.hh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/shared/item/items.hh b/src/shared/item/items.hh new file mode 100644 index 0000000..ba718c5 --- /dev/null +++ b/src/shared/item/items.hh @@ -0,0 +1,54 @@ +#ifndef SHARED_ITEM_ITEMS_HH_ +#define SHARED_ITEM_ITEMS_HH_ + +#include <memory> + +#include "shared/item/block.hh" +#include "shared/item/item.hh" +#include "shared/net/proto.hh" +#include "shared/world/block.hh" + +namespace shared { +namespace item { + +// Use this function over constructor to create a derived item. + +using item_t = std::shared_ptr<item>; +using items_t = std::array<item_t, 50>; + +using make_item_func_t = item_t (*)(const item::type_t&, const std::uint32_t&); +item_t make_item(const item::type_t& type, + const std::uint32_t& quantity) noexcept; +item_t make_item(const proto::item& item) noexcept; + +// Class for an inventory (or possibly a chest in the future, etc). +class items { +public: + items_t contents = {0}; + +public: + items() noexcept {} + items(const proto::item_array& proto) noexcept; + +public: + // Adds or removes an arbitrary amount of items to the player. + // Returns true of false based on whether the operation completed fully. + bool maybe_add(const item::type_t& type, const std::uint32_t& quantity, + const make_item_func_t& = make_item) noexcept; + bool maybe_remove(const item::type_t& type, + const std::uint32_t& quantity) noexcept; + + // Adds a single existing item, puts in new slot if necessary. + void increment(const std::uint32_t& index, + const make_item_func_t& = make_item) noexcept; + // Removes a single existing item from an index, clears if needed. + void decrement(const std::uint32_t& index) noexcept; + +public: + void pack(proto::item_array* const proto) const noexcept; +}; + +} // namespace item +} // namespace shared + +#endif |
