#include "PlaceableProof.h" #include "BlockFilter.h" #include "Dimension.h" #include "Game.h" PlaceableProof::PlaceableProof() : ReferenceCounter() {} PlaceableProofAnd::PlaceableProofAnd() : proofs(proofs) {} bool PlaceableProofAnd::isPlacable( const Item* item, Framework::Vec3 pos, int dimensionId) { for (PlaceableProof* proof : proofs) { if (!proof->isPlacable(item, pos, dimensionId)) { return false; } } return true; } void PlaceableProofAnd::addProof(PlaceableProof* proof) { proofs.add(proof); } const Framework::RCArray& PlaceableProofAnd::getProofs() const { return proofs; } PlaceableProofAndFactory::PlaceableProofAndFactory() : SubTypeFactory() {} PlaceableProofAnd* PlaceableProofAndFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new PlaceableProofAnd(); } void PlaceableProofAndFactory::fromJson( PlaceableProofAnd* zResult, Framework::JSON::JSONObject* zJson) const { for (Framework::JSON::JSONValue* zProof : *zJson->zValue("proofs")->asArray()) { zResult->addProof( Game::INSTANCE->zTypeRegistry()->fromJson(zProof)); } } void PlaceableProofAndFactory::toJson( PlaceableProofAnd* zObject, Framework::JSON::JSONObject* zResult) const { Framework::JSON::JSONArray* proofs = new Framework::JSON::JSONArray(); for (PlaceableProof* proof : zObject->getProofs()) { proofs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(proof)); } zResult->addValue("proofs", proofs); } JSONObjectValidationBuilder* PlaceableProofAndFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return builder->withRequiredArray("proofs") ->addAcceptedTypeInArray( Game::INSTANCE->zTypeRegistry()->getValidator()) ->finishArray(); } Framework::Text PlaceableProofAndFactory::getTypeToken() const { return "and"; } PlaceableProofOr::PlaceableProofOr() : proofs(proofs) {} bool PlaceableProofOr::isPlacable( const Item* item, Framework::Vec3 pos, int dimensionId) { for (PlaceableProof* proof : proofs) { if (proof->isPlacable(item, pos, dimensionId)) { return true; } } return false; } void PlaceableProofOr::addProof(PlaceableProof* proof) { proofs.add(proof); } const Framework::RCArray& PlaceableProofOr::getProofs() const { return proofs; } PlaceableProofOrFactory::PlaceableProofOrFactory() : SubTypeFactory() {} PlaceableProofOr* PlaceableProofOrFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new PlaceableProofOr(); } void PlaceableProofOrFactory::fromJson( PlaceableProofOr* zResult, Framework::JSON::JSONObject* zJson) const { for (Framework::JSON::JSONValue* zProof : *zJson->zValue("proofs")->asArray()) { zResult->addProof( Game::INSTANCE->zTypeRegistry()->fromJson(zProof)); } } void PlaceableProofOrFactory::toJson( PlaceableProofOr* zObject, Framework::JSON::JSONObject* zResult) const { Framework::JSON::JSONArray* proofs = new Framework::JSON::JSONArray(); for (PlaceableProof* proof : zObject->getProofs()) { proofs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(proof)); } zResult->addValue("proofs", proofs); } JSONObjectValidationBuilder* PlaceableProofOrFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return builder->withRequiredArray("proofs") ->addAcceptedTypeInArray( Game::INSTANCE->zTypeRegistry()->getValidator()) ->finishArray(); } Framework::Text PlaceableProofOrFactory::getTypeToken() const { return "or"; } PlaceableProofNot::PlaceableProofNot() : PlaceableProof(), proof(proof) {} PlaceableProofNot::~PlaceableProofNot() { proof->release(); } bool PlaceableProofNot::isPlacable( const Item* item, Framework::Vec3 pos, int dimensionId) { return !proof->isPlacable(item, pos, dimensionId); } void PlaceableProofNot::setProof(PlaceableProof* proof) {} PlaceableProof* PlaceableProofNot::zProof() const { return proof; } PlaceableProofNotFactory::PlaceableProofNotFactory() : SubTypeFactory() {} PlaceableProofNot* PlaceableProofNotFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new PlaceableProofNot(); } void PlaceableProofNotFactory::fromJson( PlaceableProofNot* zResult, Framework::JSON::JSONObject* zJson) const { zResult->setProof(Game::INSTANCE->zTypeRegistry()->fromJson( zJson->zValue("proof"))); } void PlaceableProofNotFactory::toJson( PlaceableProofNot* zObject, Framework::JSON::JSONObject* zResult) const { zResult->addValue( "proof", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zProof())); } JSONObjectValidationBuilder* PlaceableProofNotFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return builder->withRequiredAttribute("proof", Game::INSTANCE->zTypeRegistry()->getValidator()); } Framework::Text PlaceableProofNotFactory::getTypeToken() const { return "not"; } PlaceableProofBlockFilter::PlaceableProofBlockFilter() : PlaceableProof(), direction(NO_DIRECTION), distance(1), filter(0) {} PlaceableProofBlockFilter::~PlaceableProofBlockFilter() { filter->release(); } bool PlaceableProofBlockFilter::isPlacable( const Item* item, Framework::Vec3 pos, int dimensionId) { pos += (Framework::Vec3)(::getDirection(direction) * distance); Dimension* dim = Game::INSTANCE->zDimension(dimensionId); return dim && pos.z >= 0 && pos.z < WORLD_HEIGHT && filter->test(dim->zBlockOrDefault(pos)); } void PlaceableProofBlockFilter::setDirection(Direction direction) { this->direction = direction; } Direction PlaceableProofBlockFilter::getDirection() const { return direction; } void PlaceableProofBlockFilter::setDistance(int distance) { this->distance = distance; } int PlaceableProofBlockFilter::getDistance() const { return distance; } void PlaceableProofBlockFilter::setFilter(BlockFilter* filter) { this->filter = filter; } BlockFilter* PlaceableProofBlockFilter::zFilter() const { return filter; } PlaceableProofBlockFilterFactory::PlaceableProofBlockFilterFactory() : SubTypeFactory() {} PlaceableProofBlockFilter* PlaceableProofBlockFilterFactory::createValue( Framework::JSON::JSONObject* zJson) const { return new PlaceableProofBlockFilter(); } void PlaceableProofBlockFilterFactory::fromJson( PlaceableProofBlockFilter* zResult, Framework::JSON::JSONObject* zJson) const { Direction dir = NO_DIRECTION; if (zJson->zValue("direction")->asString()->getString().istGleich("top")) { dir = TOP; } else if (zJson->zValue("direction") ->asString() ->getString() .istGleich("bottom")) { dir = BOTTOM; } else if (zJson->zValue("direction") ->asString() ->getString() .istGleich("north")) { dir = NORTH; } else if (zJson->zValue("direction") ->asString() ->getString() .istGleich("east")) { dir = EAST; } else if (zJson->zValue("direction") ->asString() ->getString() .istGleich("south")) { dir = SOUTH; } else if (zJson->zValue("direction") ->asString() ->getString() .istGleich("west")) { dir = WEST; } zResult->setDirection(dir); zResult->setFilter(Game::INSTANCE->zTypeRegistry()->fromJson( zJson->zValue("filter"))); } void PlaceableProofBlockFilterFactory::toJson( PlaceableProofBlockFilter* zObject, Framework::JSON::JSONObject* zResult) const { Framework::Text dir = ""; if (zObject->getDirection() == NORTH) { dir = "north"; } else if (zObject->getDirection() == EAST) { dir = "east"; } else if (zObject->getDirection() == SOUTH) { dir = "south"; } else if (zObject->getDirection() == WEST) { dir = "west"; } else if (zObject->getDirection() == TOP) { dir = "top"; } else if (zObject->getDirection() == BOTTOM) { dir = "bottom"; } zResult->addValue("direction", new Framework::JSON::JSONString(dir)); zResult->addValue( "distance", new Framework::JSON::JSONNumber(zObject->getDistance())); zResult->addValue( "filter", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zFilter())); } JSONObjectValidationBuilder* PlaceableProofBlockFilterFactory::addToValidator( JSONObjectValidationBuilder* builder) const { return builder->withRequiredString("direction") ->whichIsOneOf({"top", "bottom", "north", "east", "south", "west"}) ->finishString() ->withRequiredNumber("distance") ->whichIsGreaterOrEqual(0.0) ->withDefault(1.0) ->finishNumber() ->withRequiredAttribute("filter", Game::INSTANCE->zTypeRegistry()->getValidator()); } Framework::Text PlaceableProofBlockFilterFactory::getTypeToken() const { return "blockFilter"; }