123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #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<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;
- }
|