123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include "TypeRegistry.h"
- #include "BlockTypeGeneratorRule.h"
- #include "OverworldDimension.h"
- #include "TreeTemplate.h"
- TypeRegistry::TypeRegistry()
- : ReferenceCounter()
- {
- // register dimensions
- registerDimensionGeneratorFactory(new OverworldDimensionFactory());
- // register rules
- registerGeneratorRuleFactory(new BlockTypeGeneratorRuleFactory());
- // register templates
- registerGeneratorTemplate(new TreeTemplateFactory());
- }
- void TypeRegistry::registerGeneratorRuleFactory(GeneratorRuleFactory* factory)
- {
- generatorRules.add(factory);
- }
- GeneratorRule* TypeRegistry::createGeneratorRule(
- Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
- {
- for (GeneratorRuleFactory* f : generatorRules)
- {
- Framework::JSON::Validator::JSONValidator* validator
- = f->getValidator();
- if (validator->isValid(zConfig))
- {
- validator->release();
- return f->createRule(zConfig, zMemory);
- }
- validator->release();
- }
- return 0;
- }
- Framework::JSON::Validator::JSONValidator*
- TypeRegistry::getGeneratorRuleValidator()
- {
- auto validator = Framework::JSON::Validator::JSONValidator::buildForOneOf()
- ->typeSpecifiedByAttribute("type");
- for (GeneratorRuleFactory* f : generatorRules)
- {
- validator->addAcceptedType(f->getValidator());
- }
- return validator->finishOneOf();
- }
- void TypeRegistry::registerDimensionGeneratorFactory(
- DimensionGeneratorFactory* factory)
- {
- dimensionGenerators.add(factory);
- }
- DimensionGenerator* TypeRegistry::createDimensionGenerator(
- Framework::JSON::JSONValue* zConfig, int worldSeed)
- {
- for (DimensionGeneratorFactory* f : dimensionGenerators)
- {
- Framework::JSON::Validator::JSONValidator* validator
- = f->getConfigValidator();
- if (validator->isValid(zConfig))
- {
- validator->release();
- std::cout << "Loaded Config for dimension '" << f->getName()
- << "' with id " << f->getDimensionId() << "\n";
- return f->createDimensionGenerator(worldSeed, zConfig);
- }
- validator->release();
- }
- return 0;
- }
- Framework::JSON::Validator::JSONValidator*
- TypeRegistry::getDimensionGeneratorValidator()
- {
- auto validator = Framework::JSON::Validator::JSONValidator::buildForOneOf()
- ->typeSpecifiedByAttribute("dimension");
- for (DimensionGeneratorFactory* f : dimensionGenerators)
- {
- validator->addAcceptedType(f->getConfigValidator());
- }
- return validator->finishOneOf();
- }
- const Framework::RCArray<DimensionGeneratorFactory>&
- TypeRegistry::getDimensionGeneratorFactories() const
- {
- return dimensionGenerators;
- }
- void TypeRegistry::registerGeneratorTemplate(GeneratorTemplateFactory* factory)
- {
- generatorTemplates.add(factory);
- }
- GeneratorTemplate* TypeRegistry::createGeneratorTemplate(
- Framework::JSON::JSONValue* zConfig)
- {
- for (GeneratorTemplateFactory* f : generatorTemplates)
- {
- Framework::JSON::Validator::JSONValidator* validator
- = f->getValidator();
- if (validator->isValid(zConfig))
- {
- validator->release();
- return f->createTemplate(zConfig);
- }
- validator->release();
- }
- return 0;
- }
- Framework::JSON::Validator::JSONValidator*
- TypeRegistry::getGeneratorTemplateValidator()
- {
- auto validator = Framework::JSON::Validator::JSONValidator::buildForOneOf()
- ->typeSpecifiedByAttribute("type");
- for (GeneratorTemplateFactory* f : generatorTemplates)
- {
- validator->addAcceptedType(f->getValidator());
- }
- return validator->finishOneOf();
- }
|