ItemSlot.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 allowedPullSide;
  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. int allowedPullSides,
  34. int allowedPushSides,
  35. bool allowHigherStackSize);
  36. ~ItemSlot();
  37. ItemStack* takeItemsOut(int count, Direction dir);
  38. void addItems(ItemStack* zStack, Direction dir);
  39. void update();
  40. int numberOfAddableItems(const Item* zItem, Direction dir) const;
  41. const ItemStack* zStack() const;
  42. int getPullPriority() const;
  43. int getPushPriority() const;
  44. bool isFull() const;
  45. int getFreeSpace() const;
  46. bool isEmpty() const;
  47. int getNumberOfItems() const;
  48. const Framework::Text& getName() const;
  49. int getId() const;
  50. friend class ItemSlotFactory;
  51. };
  52. class ItemSlotFactory : public ObjectTypeFactory<ItemSlot>
  53. {
  54. public:
  55. ItemSlotFactory();
  56. JSONObjectValidationBuilder* addToValidator(
  57. JSONObjectValidationBuilder* builder) const override;
  58. ItemSlot* fromJson(Framework::JSON::JSONObject* zJson) const override;
  59. Framework::JSON::JSONObject* toJsonObject(ItemSlot* zObject) const override;
  60. };