#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 BlockInstanceGeneratorRule::createBlock( int x, int y, int z, int dimensionId) { return Game::INSTANCE->zBlockType(blockType)->createBlockAt( Framework::Vec3(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 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(); }