#pragma once #include #include #include "GeneratedStructure.h" #include "Noise.h" class GeneratorTemplate : public Framework::ReferenceCounter { private: float propability; Framework::Vec3 minPosOffset; Framework::Vec3 maxSize; public: GeneratorTemplate(); protected: void setMinPosOffset(Framework::Vec3 minPosOffset); void setMaxSize(Framework::Vec3 maxSize); public: void setPropability(float propability); virtual bool canEffect(Framework::Vec3 location, Framework::Vec3 affectedLocation) const; virtual GeneratedStructure* generateAt( Framework::Vec3 location, Noise* zNoise, int dimensionId) = 0; float getPropability() const; Framework::Vec3 getMinAffectedOffset() const; Framework::Vec3 getMaxAffectedOffset() const; }; template class GeneratorTemplateFactory : public SubTypeFactory { public: GeneratorTemplateFactory() : SubTypeFactory() {} S* fromJson(Framework::JSON::JSONObject* zJson) const override { S* result = createValue(zJson); GeneratorTemplate* zRecipie = dynamic_cast(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(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; };