123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "BlockInstanceGeneratorRule.h"
- #include "Game.h"
- BlockInstanceGeneratorRule::BlockInstanceGeneratorRule()
- : GeneratorRule(),
- blockType(0)
- {}
- 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);
- }
- 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<Framework::Text>(
- BlockTypeNameFactory::TYPE_ID)));
- }
- const char* BlockInstanceGeneratorRuleFactory::getTypeToken() const
- {
- return "blockInstance";
- }
|