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.

Item.h 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <string>
  3. #include "Resource.h"
  4. namespace Swan {
  5. // TODO: Switch to struct
  6. class Item {
  7. public:
  8. struct Builder {
  9. std::string name;
  10. std::string image;
  11. int maxStack = 64;
  12. };
  13. Item(const ResourceManager &resources, const Builder &builder):
  14. name_(builder.name), image_(resources.getImage(builder.image)),
  15. maxStack_(builder.maxStack) {}
  16. const std::string name_;
  17. const ImageResource &image_;
  18. const int maxStack_;
  19. static std::unique_ptr<Item> createInvalid(Context &ctx);
  20. // For testing, we want to be able to create Items without an actual ImageResource.
  21. // Tests can create a MockItem class which inherits from Item and uses this ctor,
  22. // as long as the test never does anything which tries to follow the image_ member.
  23. // Eventually, this should become unnecessary, because we don't need to require
  24. // a complete ImageResource for a headless server, but for now, this will suffice.
  25. protected:
  26. Item(const Builder &builder):
  27. name_(builder.name), image_(*(ImageResource *)this),
  28. maxStack_(builder.maxStack) {}
  29. };
  30. }