12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #pragma once
- #include <ReferenceCounter.h>
- #include <Vec3.h>
- #include "GeneratedStructure.h"
- #include "Noise.h"
- class GeneratorTemplate : public Framework::ReferenceCounter
- {
- private:
- float propability;
- Framework::Vec3<int> minPosOffset;
- Framework::Vec3<int> maxSize;
- public:
- GeneratorTemplate();
- protected:
- void setMinPosOffset(Framework::Vec3<int> minPosOffset);
- void setMaxSize(Framework::Vec3<int> maxSize);
- public:
- void setPropability(float propability);
- virtual bool canEffect(Framework::Vec3<int> location,
- Framework::Vec3<int> affectedLocation) const;
- virtual GeneratedStructure* generateAt(
- Framework::Vec3<int> location, Noise* zNoise, int dimensionId)
- = 0;
- float getPropability() const;
- Framework::Vec3<int> getMinAffectedOffset() const;
- Framework::Vec3<int> getMaxAffectedOffset() const;
- };
- template<typename S> class GeneratorTemplateFactory
- : public SubTypeFactory<GeneratorTemplate, S>
- {
- public:
- GeneratorTemplateFactory()
- : SubTypeFactory<GeneratorTemplate, S>()
- {}
- S* fromJson(Framework::JSON::JSONObject* zJson) const override
- {
- S* result = createValue(zJson);
- GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(result);
- zRecipie->setPropability(
- (float)zJson->zValue("propability")->asNumber()->getNumber());
- return result;
- }
- Framework::JSON::JSONObject* toJsonObject(S* zObject) const override
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(result);
- result->addValue("propability",
- new Framework::JSON::JSONNumber(zRecipie->getPropability()));
- return result;
- };
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override
- {
- return builder->withRequiredNumber("propability")->finishNumber();
- }
- protected:
- virtual S* createValue(Framework::JSON::JSONObject* zJson) const = 0;
- };
|