123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #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>()
- {}
- void fromJson(S* zResult, Framework::JSON::JSONObject* zJson) const override
- {
- GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(zResult);
- zRecipie->setPropability(
- (float)zJson->zValue("propability")->asNumber()->getNumber());
- }
- void toJson(S* zObject, Framework::JSON::JSONObject* zResult) const override
- {
- GeneratorTemplate* zRecipie = dynamic_cast<GeneratorTemplate*>(zResult);
- zResult->addValue("propability",
- new Framework::JSON::JSONNumber(zRecipie->getPropability()));
- };
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override
- {
- return builder->withRequiredNumber("propability")->finishNumber();
- }
- };
|