1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #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();
- }
- void BlockInstanceGeneratorRuleFactory::fromJson(
- BlockInstanceGeneratorRule* zResult,
- Framework::JSON::JSONObject* zJson) const
- {
- zResult->setBlockTypeId(Game::INSTANCE->getBlockTypeId(
- zJson->zValue("blockType")->asString()->getString()));
- GeneratorRuleFactory::fromJson(zResult, zJson);
- }
- void BlockInstanceGeneratorRuleFactory::toJson(
- BlockInstanceGeneratorRule* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("blockType",
- new Framework::JSON::JSONString(
- Game::INSTANCE->zBlockType(zObject->getBlockTypeId())->getName()));
- GeneratorRuleFactory::toJson(zObject, zResult);
- }
- JSONObjectValidationBuilder* BlockInstanceGeneratorRuleFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- 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 GeneratorRuleFactory::addToValidator(
- builder->withRequiredString("blockType")
- ->whichIsOneOf(blockTypeNames)
- ->finishString());
- }
- Framework::Text BlockInstanceGeneratorRuleFactory::getTypeToken() const
- {
- return "blockInstance";
- }
|