GeneratorTemplate.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <ReferenceCounter.h>
  3. #include <Vec3.h>
  4. #include "GeneratedStructure.h"
  5. #include "Noise.h"
  6. class GeneratorTemplate : public Framework::ReferenceCounter
  7. {
  8. private:
  9. float propability;
  10. Framework::Vec3<int> minPosOffset;
  11. Framework::Vec3<int> maxSize;
  12. public:
  13. GeneratorTemplate();
  14. protected:
  15. void setMinPosOffset(Framework::Vec3<int> minPosOffset);
  16. void setMaxSize(Framework::Vec3<int> maxSize);
  17. public:
  18. void setPropability(float propability);
  19. virtual bool canEffect(Framework::Vec3<int> location,
  20. Framework::Vec3<int> affectedLocation) const;
  21. virtual GeneratedStructure* generateAt(
  22. Framework::Vec3<int> location, Noise* zNoise, int dimensionId)
  23. = 0;
  24. float getPropability() const;
  25. Framework::Vec3<int> getMinAffectedOffset() const;
  26. Framework::Vec3<int> getMaxAffectedOffset() const;
  27. };
  28. template<typename S> class GeneratorTemplateFactory
  29. : public SubTypeFactory<GeneratorTemplate, S>
  30. {
  31. public:
  32. GeneratorTemplateFactory()
  33. : SubTypeFactory<GeneratorTemplate, S>()
  34. {}
  35. S* fromJson(Framework::JSON::JSONObject* zJson) const override
  36. {
  37. S* result = createValue(zJson);
  38. GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(result);
  39. zRecipie->setPropability(
  40. (float)zJson->zValue("propability")->asNumber()->getNumber());
  41. return result;
  42. }
  43. Framework::JSON::JSONObject* toJsonObject(S* zObject) const override
  44. {
  45. Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
  46. GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(result);
  47. result->addValue("propability",
  48. new Framework::JSON::JSONNumber(zRecipie->getPropability()));
  49. return result;
  50. };
  51. JSONObjectValidationBuilder* addToValidator(
  52. JSONObjectValidationBuilder* builder) const override
  53. {
  54. return builder->withRequiredNumber("propability")->finishNumber();
  55. }
  56. protected:
  57. virtual S* createValue(Framework::JSON::JSONObject* zJson) const = 0;
  58. };