TypeRegistry.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "TypeRegistry.h"
  2. #include "BasicBlocks.h"
  3. #include "BasicItems.h"
  4. #include "BasicTool.h"
  5. #include "BlockFilter.h"
  6. #include "BlockInstanceGeneratorRule.h"
  7. #include "BlockTypeGeneratorRule.h"
  8. #include "Chest.h"
  9. #include "Dimension.h"
  10. #include "DimensionGenerator.h"
  11. #include "FluidBlock.h"
  12. #include "FluidContainer.h"
  13. #include "GeneratorRule.h"
  14. #include "Grass.h"
  15. #include "GrowingPlant.h"
  16. #include "LightSources.h"
  17. #include "ModelInfo.h"
  18. #include "OverworldDimension.h"
  19. #include "OverworldDimensionGenerator.h"
  20. #include "PlaceableProof.h"
  21. #include "Quest.h"
  22. #include "Recipie.h"
  23. #include "TreeSeblingBlock.h"
  24. #include "TreeTemplate.h"
  25. TypeRegistry::TypeRegistry()
  26. : ReferenceCounter()
  27. {
  28. // register dimension generators
  29. registerDimensionGeneratorFactory(new OverworldDimensionGeneratorFactory());
  30. // register dimensions
  31. registerDimension(new OverworldDimensionFactory());
  32. // register rules
  33. registerGeneratorRuleFactory(new BlockTypeGeneratorRuleFactory());
  34. registerGeneratorRuleFactory(new BlockInstanceGeneratorRuleFactory());
  35. // register templates
  36. registerSubType(new TreeTemplateFactory());
  37. // register quest datastructures
  38. registerType(new QuestRequirementStorageType());
  39. registerType(new QuestStorageType());
  40. registerType(new QuestPartyType());
  41. registerType(new QuestType());
  42. registerType(new QuestCollectionType());
  43. registerSubType(new QuestRequirementOpenDialogType());
  44. registerType(new ItemJsonType());
  45. registerType(new ItemStackInfoType());
  46. registerSubType(new QuestRewardGiveItemsType());
  47. // block types
  48. registerType(new ModelInfoFactory());
  49. registerSubType(new BasicBlockTypeFactory());
  50. registerSubType(new AdditionalItemSpawningBlockTypeFactory());
  51. registerSubType(new BasicLightSourceBlockTypeFactory());
  52. registerSubType(new ChestBlockTypeFactory());
  53. registerSubType(new FluidBlockTypeFactory());
  54. registerSubType(new GrassBlockTypeFactory());
  55. registerSubType(new GrowingPlantBlockTypeFactory());
  56. registerSubType(new TreeSeblingBlockTypeFactory());
  57. // block filter
  58. registerSubType(new BlockFilterAndFactory());
  59. registerSubType(new BlockFilterOrFactory());
  60. registerSubType(new BlockFilterNotFactory());
  61. registerSubType(new BlockFilterBlockTypeFactory());
  62. registerSubType(new BlockFilterTypeGroupFactory());
  63. registerSubType(new BlockFilterMaxHardnessFactory());
  64. registerSubType(new BlockFilterMinHardnessFactory());
  65. registerSubType(new BlockFilterMaxHeatFactory());
  66. // placeable proof
  67. registerSubType(new PlaceableProofAndFactory());
  68. registerSubType(new PlaceableProofOrFactory());
  69. registerSubType(new PlaceableProofNotFactory());
  70. registerSubType(new PlaceableProofBlockFilterFactory());
  71. // item types
  72. registerSubType(new BasicBlockItemTypeFactory());
  73. registerSubType(new BasicItemTypeFactory());
  74. registerSubType(new BasicToolItemTypeFactory());
  75. registerSubType(new FluidContainerItemTypeFactory());
  76. // item skills
  77. registerSubType(new XPBasedLevelUpRuleFactory());
  78. registerType(new DamagingItemSkillConfigFactory());
  79. registerSubType(new DamagingItemSkillFactory());
  80. registerType(new BlockReplaceItemSkillConfigFactory());
  81. registerSubType(new BlockReplaceItemSkillFactory());
  82. registerType(new FluidContainerItemSkillConfigFactory());
  83. registerSubType(new FluidContainerItemSkillFactory());
  84. // reipies
  85. registerType(new RecipieInputFactory());
  86. registerType(new RecipieOutputFactory());
  87. registerSubType(new ShapedRecipieFactory());
  88. registerSubType(new UnshapedRecipieFactory());
  89. // item modifiers
  90. registerSubType(new ConsumeItemModifierFactory());
  91. registerSubType(new DoNothingModifierFactory());
  92. registerSubType(new AttributeItemModifierFactory());
  93. registerSubType(new CombinedItemModifierFactory());
  94. // item filters
  95. registerSubType(new CombinedItemFilterFactory());
  96. registerSubType(new AnyItemFilterFactory());
  97. registerSubType(new TypeItemFilterFactory());
  98. registerSubType(new GroupItemFilterFactory());
  99. }
  100. void TypeRegistry::registerGeneratorRuleFactory(GeneratorRuleFactory* factory)
  101. {
  102. generatorRules.add(factory);
  103. }
  104. GeneratorRule* TypeRegistry::createGeneratorRule(
  105. Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
  106. {
  107. for (GeneratorRuleFactory* f : generatorRules)
  108. {
  109. Framework::JSON::Validator::JSONValidator* validator
  110. = f->getValidator();
  111. if (validator->isValid(zConfig))
  112. {
  113. validator->release();
  114. return f->createRule(zConfig, zMemory);
  115. }
  116. validator->release();
  117. }
  118. return 0;
  119. }
  120. Framework::JSON::Validator::JSONValidator*
  121. TypeRegistry::getGeneratorRuleValidator()
  122. {
  123. auto validator = Framework::JSON::Validator::JSONValidator::buildForOneOf()
  124. ->typeSpecifiedByAttribute("type");
  125. for (GeneratorRuleFactory* f : generatorRules)
  126. {
  127. validator->addAcceptedType(f->getValidator());
  128. }
  129. return validator->finishOneOf();
  130. }
  131. void TypeRegistry::registerDimensionGeneratorFactory(
  132. DimensionGeneratorFactory* factory)
  133. {
  134. dimensionGenerators.add(factory);
  135. }
  136. DimensionGenerator* TypeRegistry::createDimensionGenerator(
  137. Framework::JSON::JSONValue* zConfig, int worldSeed)
  138. {
  139. for (DimensionGeneratorFactory* f : dimensionGenerators)
  140. {
  141. Framework::JSON::Validator::JSONValidator* validator
  142. = f->getConfigValidator();
  143. if (validator->isValid(zConfig))
  144. {
  145. validator->release();
  146. std::cout << "Loaded Config for dimension '" << f->getName()
  147. << "' with id " << f->getDimensionId() << "\n";
  148. return f->createDimensionGenerator(worldSeed, zConfig);
  149. }
  150. validator->release();
  151. }
  152. return 0;
  153. }
  154. Framework::JSON::Validator::JSONValidator*
  155. TypeRegistry::getDimensionGeneratorValidator()
  156. {
  157. auto validator = Framework::JSON::Validator::JSONValidator::buildForOneOf()
  158. ->typeSpecifiedByAttribute("dimension");
  159. for (DimensionGeneratorFactory* f : dimensionGenerators)
  160. {
  161. validator->addAcceptedType(f->getConfigValidator());
  162. }
  163. return validator->finishOneOf();
  164. }
  165. const Framework::RCArray<DimensionGeneratorFactory>&
  166. TypeRegistry::getDimensionGeneratorFactories() const
  167. {
  168. return dimensionGenerators;
  169. }
  170. void TypeRegistry::registerDimension(DimensionFactory* factory)
  171. {
  172. dimensionFactories.add(factory);
  173. }
  174. Dimension* TypeRegistry::createDimension(int id)
  175. {
  176. for (DimensionFactory* factory : dimensionFactories)
  177. {
  178. if (factory->getDimensionId() == id)
  179. {
  180. return factory->createDimension();
  181. }
  182. }
  183. return 0;
  184. }