A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InventoryTrait.h 877B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <vector>
  3. #include <stdlib.h>
  4. #include "../common.h"
  5. #include "../ItemStack.h"
  6. namespace Swan {
  7. struct InventoryTrait {
  8. struct Tag {};
  9. struct Inventory {
  10. virtual ~Inventory() = default;
  11. virtual int size() = 0;
  12. virtual ItemStack get(int slot) = 0;
  13. virtual ItemStack set(int slot, ItemStack stack) = 0;
  14. virtual ItemStack insert(int slot, ItemStack stack) = 0;
  15. ItemStack insert(ItemStack stack) { return insert(0, stack); }
  16. };
  17. virtual ~InventoryTrait() = default;
  18. virtual Inventory &get(Tag) = 0;
  19. };
  20. struct BasicInventory final: InventoryTrait::Inventory {
  21. BasicInventory(int size): content(size) {}
  22. std::vector<ItemStack> content;
  23. int size() override { return content.size(); }
  24. ItemStack get(int slot) override;
  25. ItemStack set(int slot, ItemStack stack) override;
  26. ItemStack insert(int slot, ItemStack stack) override;
  27. };
  28. }