123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include "BlockInstanceGeneratorRule.h"
- #include "Game.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 Game::INSTANCE->zBlockType(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 < Game::INSTANCE->getBlockTypeCount(); i++)
- {
- if (Game::INSTANCE->zBlockType(i))
- {
- blockTypeNames.add(
- new Framework::Text(Game::INSTANCE->zBlockType(i)->getName()));
- }
- }
- return GeneratorRule::addToValidator(
- Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredString("type")
- ->withExactMatch("blockInstance")
- ->finishString()
- ->withRequiredString("blockType")
- ->whichIsOneOf(blockTypeNames)
- ->finishString())
- ->finishObject();
- }
|