#include "TypeRegistry.h" #include "BasicBlocks.h" #include "BasicItems.h" #include "BasicTool.h" #include "BlockFilter.h" #include "BlockInstanceGeneratorRule.h" #include "BlockTypeGeneratorRule.h" #include "Chest.h" #include "Dimension.h" #include "DimensionGenerator.h" #include "FluidBlock.h" #include "FluidContainer.h" #include "GeneratorRule.h" #include "Grass.h" #include "GrowingPlant.h" #include "LightSources.h" #include "ModelInfo.h" #include "OverworldDimension.h" #include "OverworldDimensionGenerator.h" #include "PlaceableProof.h" #include "Quest.h" #include "Recipie.h" #include "TreeSeblingBlock.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 ItemJsonType()); registerType(new ItemStackInfoType()); registerSubType(new QuestRewardGiveItemsType()); // block types registerType(new ModelInfoFactory()); registerSubType(new BasicBlockTypeFactory()); registerSubType(new AdditionalItemSpawningBlockTypeFactory()); registerSubType(new BasicLightSourceBlockTypeFactory()); registerSubType(new ChestBlockTypeFactory()); registerSubType(new FluidBlockTypeFactory()); registerSubType(new GrassBlockTypeFactory()); registerSubType(new GrowingPlantBlockTypeFactory()); registerSubType(new TreeSeblingBlockTypeFactory()); // block filter registerSubType(new BlockFilterAndFactory()); registerSubType(new BlockFilterOrFactory()); registerSubType(new BlockFilterNotFactory()); registerSubType(new BlockFilterBlockTypeFactory()); registerSubType(new BlockFilterTypeGroupFactory()); registerSubType(new BlockFilterMaxHardnessFactory()); registerSubType(new BlockFilterMinHardnessFactory()); registerSubType(new BlockFilterMaxHeatFactory()); // placeable proof registerSubType(new PlaceableProofAndFactory()); registerSubType(new PlaceableProofOrFactory()); registerSubType(new PlaceableProofNotFactory()); registerSubType(new PlaceableProofBlockFilterFactory()); // item types registerSubType(new BasicBlockItemTypeFactory()); registerSubType(new BasicItemTypeFactory()); registerSubType(new BasicToolItemTypeFactory()); registerSubType(new FluidContainerItemTypeFactory()); // item skills registerSubType(new XPBasedLevelUpRuleFactory()); registerType(new DamagingItemSkillConfigFactory()); registerSubType(new DamagingItemSkillFactory()); registerType(new BlockReplaceItemSkillConfigFactory()); registerSubType(new BlockReplaceItemSkillFactory()); registerType(new FluidContainerItemSkillConfigFactory()); registerSubType(new FluidContainerItemSkillFactory()); // reipies registerType(new RecipieInputFactory()); registerType(new RecipieOutputFactory()); registerSubType(new ShapedRecipieFactory()); registerSubType(new UnshapedRecipieFactory()); // item modifiers registerSubType(new ConsumeItemModifierFactory()); registerSubType(new DoNothingModifierFactory()); registerSubType(new AttributeItemModifierFactory()); registerSubType(new CombinedItemModifierFactory()); // item filters registerSubType(new CombinedItemFilterFactory()); registerSubType(new AnyItemFilterFactory()); registerSubType(new TypeItemFilterFactory()); registerSubType(new GroupItemFilterFactory()); } 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& 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; }