GeneratorTemplate.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. void fromJson(S* zResult, Framework::JSON::JSONObject* zJson) const override
  36. {
  37. GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(zResult);
  38. zRecipie->setPropability(
  39. (float)zJson->zValue("propability")->asNumber()->getNumber());
  40. }
  41. void toJson(S* zObject, Framework::JSON::JSONObject* zResult) const override
  42. {
  43. GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(zResult);
  44. zResult->addValue("propability",
  45. new Framework::JSON::JSONNumber(zRecipie->getPropability()));
  46. };
  47. JSONObjectValidationBuilder* addToValidator(
  48. JSONObjectValidationBuilder* builder) const override
  49. {
  50. return builder->withRequiredNumber("propability")->finishNumber();
  51. }
  52. };