#include "BlockInstanceGeneratorRule.h" #include "Game.h" BlockInstanceGeneratorRule::BlockInstanceGeneratorRule() : GeneratorRule(), blockType(0) {} 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); } void BlockInstanceGeneratorRule::setBlockTypeId(int blockType) { this->blockType = blockType; } int BlockInstanceGeneratorRule::getBlockTypeId() const { return blockType; } BlockInstanceGeneratorRuleFactory::BlockInstanceGeneratorRuleFactory() : GeneratorRuleFactory() {} BlockInstanceGeneratorRule* BlockInstanceGeneratorRuleFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new BlockInstanceGeneratorRule(); } BlockInstanceGeneratorRule* BlockInstanceGeneratorRuleFactory::fromJson( Framework::JSON::JSONObject* zJson) const { BlockInstanceGeneratorRule* result = GeneratorRuleFactory::fromJson(zJson); result->setBlockTypeId(Game::INSTANCE->getBlockTypeId( zJson->zValue("blockType")->asString()->getString())); return result; } Framework::JSON::JSONObject* BlockInstanceGeneratorRuleFactory::toJsonObject( BlockInstanceGeneratorRule* zObject) const { Framework::JSON::JSONObject* result = GeneratorRuleFactory::toJsonObject(zObject); result->addValue("blockType", new Framework::JSON::JSONString( Game::INSTANCE->zBlockType(zObject->getBlockTypeId())->getName())); return result; } JSONObjectValidationBuilder* BlockInstanceGeneratorRuleFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return GeneratorRuleFactory::addToValidator( builder->withRequiredAttribute("blockType", Game::INSTANCE->zTypeRegistry()->getValidator( BlockTypeNameFactory::TYPE_ID))); } const char* BlockInstanceGeneratorRuleFactory::getTypeToken() const { return "blockInstance"; }