123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "BlockInstanceGeneratorRule.h"
- BlockInstanceGeneratorRule::BlockInstanceGeneratorRule(
- Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
- : GeneratorRule(zConfig, zMemory)
- {
- blockType = BlockType::getTypeId(
- zConfig->asObject()->zValue("blockType")->asString()->getString());
- }
- Framework::Either<Block*, int> BlockInstanceGeneratorRule::createBlock(
- int x, int y, int z, int dimensionId)
- {
- return StaticRegistry<BlockType>::INSTANCE.zElement(blockType)->createBlockAt(Framework::Vec3<int>(x, y, z), dimensionId, 0);
- }
- BlockInstanceGeneratorRuleFactory::BlockInstanceGeneratorRuleFactory()
- : ReferenceCounter()
- {}
- GeneratorRule* BlockInstanceGeneratorRuleFactory::createRule(
- Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
- {
- return new BlockInstanceGeneratorRule(zConfig, zMemory);
- }
- Framework::JSON::Validator::JSONValidator*
- BlockInstanceGeneratorRuleFactory::getValidator()
- {
- Framework::RCArray<Framework::Text> blockTypeNames;
- for (int i = 0; i < StaticRegistry<BlockType>::INSTANCE.getCount(); i++)
- {
- if (StaticRegistry<BlockType>::INSTANCE.zElement(i))
- {
- blockTypeNames.add(new Framework::Text(
- StaticRegistry<BlockType>::INSTANCE.zElement(i)->getName()));
- }
- }
- return GeneratorRule::addToValidator(
- Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredString("type")
- ->withExactMatch("blockInstance")
- ->finishString()
- ->withRequiredString("blockType")
- ->whichIsOneOf(blockTypeNames)
- ->finishString())
- ->finishObject();
- }
|