ItemSlot.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <Text.h>
  3. #include "Area.h"
  4. #include "TypeRegistry.h"
  5. class Inventory;
  6. class ItemStack;
  7. class Item;
  8. class ItemSlotIDSetter
  9. {
  10. protected:
  11. virtual void setId(int id) = 0;
  12. friend Inventory;
  13. };
  14. class ItemSlot : public virtual Framework::ReferenceCounter,
  15. public ItemSlotIDSetter
  16. {
  17. private:
  18. ItemStack* items;
  19. int maxSize;
  20. Directions allowedPullSides;
  21. Directions allowedPushSides;
  22. int pullPriority;
  23. int pushPriority;
  24. bool allowHigherStackSize;
  25. Framework::Text name;
  26. int id;
  27. void setId(int id) override;
  28. public:
  29. ItemSlot(Framework::Text name,
  30. int maxSize,
  31. int pullPriority,
  32. int pushPriority,
  33. Directions allowedPullSides,
  34. Directions allowedPushSides,
  35. bool allowHigherStackSize);
  36. ItemSlot(ItemSlot& slot);
  37. ~ItemSlot();
  38. ItemStack* takeItemsOut(int count, Direction dir);
  39. void addItems(ItemStack* zStack, Direction dir);
  40. void update();
  41. int numberOfAddableItems(const Item* zItem, Direction dir) const;
  42. const ItemStack* zStack() const;
  43. int getPullPriority() const;
  44. int getPushPriority() const;
  45. bool isFull() const;
  46. int getFreeSpace() const;
  47. bool isEmpty() const;
  48. int getNumberOfItems() const;
  49. const Framework::Text& getName() const;
  50. int getId() const;
  51. friend class ItemSlotFactory;
  52. };
  53. class ItemSlotFactory : public ObjectTypeFactory<ItemSlot>
  54. {
  55. public:
  56. ItemSlotFactory();
  57. JSONObjectValidationBuilder* addToValidator(
  58. JSONObjectValidationBuilder* builder) const override;
  59. ItemSlot* fromJson(Framework::JSON::JSONObject* zJson) const override;
  60. Framework::JSON::JSONObject* toJsonObject(ItemSlot* zObject) const override;
  61. };