GeneratorRule.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. };
  40. class GeneratorRuleFactory : public virtual Framework::ReferenceCounter
  41. {
  42. public:
  43. GeneratorRuleFactory();
  44. virtual GeneratorRule* createRule(
  45. Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
  46. = 0;
  47. virtual Framework::JSON::Validator::JSONValidator* getValidator() = 0;
  48. };