123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- #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<float> 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<PlaceableProof>& 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<PlaceableProof>(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<PlaceableProof>())
- ->finishArray();
- }
- Framework::Text PlaceableProofAndFactory::getTypeToken() const
- {
- return "and";
- }
- PlaceableProofOr::PlaceableProofOr()
- : proofs(proofs)
- {}
- bool PlaceableProofOr::isPlacable(
- const Item* item, Framework::Vec3<float> 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<PlaceableProof>& 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<PlaceableProof>(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<PlaceableProof>())
- ->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<float> 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<PlaceableProof>(
- 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<PlaceableProof>());
- }
- 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<float> pos, int dimensionId)
- {
- pos += (Framework::Vec3<float>)(::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<BlockFilter>(
- 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<BlockFilter>());
- }
- Framework::Text PlaceableProofBlockFilterFactory::getTypeToken() const
- {
- return "blockFilter";
- }
|