| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "BlockInstanceGeneratorRule.h"
- #include "BlockType.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";
- }
|