GeneratorRule.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <Either.h>
  3. #include <JSON.h>
  4. #include "Block.h"
  5. #include "JNoise.h"
  6. #include "JsonExpression.h"
  7. class GeneratorRule : public virtual Framework::ReferenceCounter
  8. {
  9. private:
  10. Noise* noise;
  11. float threshold;
  12. JBoolExpression* condition;
  13. protected:
  14. virtual Framework::Either<Block*, int> createBlock(
  15. int x, int y, int z, int dimensionId)
  16. = 0;
  17. public:
  18. GeneratorRule(
  19. Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory);
  20. ~GeneratorRule();
  21. bool checkCondition(int x, int y, int z, JExpressionMemory* zMemory);
  22. Framework::Either<Block*, int> generateBlock(
  23. int x, int y, int z, int dimensionId);
  24. template<class T>
  25. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  26. addToValidator(
  27. Framework::JSON::Validator::ObjectValidationBuilder<T>* builder)
  28. {
  29. return builder
  30. ->withRequiredAttribute("noise", JNoise::getValidator(true))
  31. ->withRequiredAttribute(
  32. "condition", JExpressionParser::getBoolValidator())
  33. ->withRequiredNumber("threshold")
  34. ->whichIsOptional()
  35. ->whichIsGreaterOrEqual(0.0)
  36. ->whichIsLessOrEqual(1.0)
  37. ->finishNumber();
  38. }
  39. };