ItemSlot.h 1.7 KB

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