123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include "TypeRegistry.h"
- #include "BlockInstanceGeneratorRule.h"
- #include "BlockTypeGeneratorRule.h"
- #include "Dimension.h"
- #include "DimensionGenerator.h"
- #include "GeneratorRule.h"
- #include "OverworldDimension.h"
- #include "OverworldDimensionGenerator.h"
- #include "Quest.h"
- #include "TreeTemplate.h"
- TypeRegistry::TypeRegistry()
- : ReferenceCounter()
- {
- // register dimension generators
- registerDimensionGeneratorFactory(new OverworldDimensionGeneratorFactory());
- // register dimensions
- registerDimension(new OverworldDimensionFactory());
- // register rules
- registerGeneratorRuleFactory(new BlockTypeGeneratorRuleFactory());
- registerGeneratorRuleFactory(new BlockInstanceGeneratorRuleFactory());
- // register templates
- registerSubType(new TreeTemplateFactory());
- // register quest datastructures
- registerType(new QuestRequirementStorageType());
- registerType(new QuestStorageType());
- registerType(new QuestPartyType());
- registerType(new QuestType());
- registerType(new QuestCollectionType());
- registerSubType(new QuestRequirementOpenDialogType());
- registerType(new ItomJsonType());
- registerType(new ItemStackInfoType());
- registerSubType(new QuestRewardGiveItemsType());
- }
- 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::registerDimension(DimensionFactory* factory)
- {
- dimensionFactories.add(factory);
- }
- Dimension* TypeRegistry::createDimension(int id)
- {
- for (DimensionFactory* factory : dimensionFactories)
- {
- if (factory->getDimensionId() == id)
- {
- return factory->createDimension();
- }
- }
- return 0;
- }
|