123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- #include "PlaceableProof.h"
- #include "BlockFilter.h"
- #include "Game.h"
- PlaceableProof::PlaceableProof()
- : ReferenceCounter()
- {}
- PlaceableProofAnd::PlaceableProofAnd(Framework::RCArray<PlaceableProof> proofs)
- : 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;
- }
- const Framework::RCArray<PlaceableProof>& PlaceableProofAnd::getProofs() const
- {
- return proofs;
- }
- PlaceableProofAndFactory::PlaceableProofAndFactory()
- : SubTypeFactory()
- {}
- PlaceableProofAnd* PlaceableProofAndFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::RCArray<PlaceableProof> proofs;
- for (Framework::JSON::JSONValue* zProof :
- *zJson->zValue("proofs")->asArray())
- {
- proofs.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<PlaceableProof>(zProof));
- }
- return new PlaceableProofAnd(proofs);
- }
- Framework::JSON::JSONObject* PlaceableProofAndFactory::toJson(
- PlaceableProofAnd* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- Framework::JSON::JSONArray* proofs = new Framework::JSON::JSONArray();
- for (PlaceableProof* proof : zObject->getProofs())
- {
- proofs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(proof));
- }
- result->addValue("proofs", proofs);
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- PlaceableProofAndFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredArray("proofs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<PlaceableProof>())
- ->finishArray()
- ->finishObject();
- }
- Framework::Text PlaceableProofAndFactory::getTypeToken() const
- {
- return "and";
- }
- PlaceableProofOr::PlaceableProofOr(Framework::RCArray<PlaceableProof> proofs)
- : 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;
- }
- const Framework::RCArray<PlaceableProof>& PlaceableProofOr::getProofs() const
- {
- return proofs;
- }
- PlaceableProofOrFactory::PlaceableProofOrFactory()
- : SubTypeFactory()
- {}
- PlaceableProofOr* PlaceableProofOrFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::RCArray<PlaceableProof> proofs;
- for (Framework::JSON::JSONValue* zProof :
- *zJson->zValue("proofs")->asArray())
- {
- proofs.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<PlaceableProof>(zProof));
- }
- return new PlaceableProofOr(proofs);
- }
- Framework::JSON::JSONObject* PlaceableProofOrFactory::toJson(
- PlaceableProofOr* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- Framework::JSON::JSONArray* proofs = new Framework::JSON::JSONArray();
- for (PlaceableProof* proof : zObject->getProofs())
- {
- proofs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(proof));
- }
- result->addValue("proofs", proofs);
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- PlaceableProofOrFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredArray("proofs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<PlaceableProof>())
- ->finishArray()
- ->finishObject();
- }
- Framework::Text PlaceableProofOrFactory::getTypeToken() const
- {
- return "or";
- }
- PlaceableProofNot::PlaceableProofNot(PlaceableProof* proof)
- : PlaceableProof()
- {}
- PlaceableProofNot::~PlaceableProofNot()
- {
- proof->release();
- }
- bool PlaceableProofNot::isPlacable(
- const Item* item, Framework::Vec3<float> pos, int dimensionId)
- {
- return !proof->isPlacable(item, pos, dimensionId);
- }
- PlaceableProof* PlaceableProofNot::zProof() const
- {
- return proof;
- }
- PlaceableProofNotFactory::PlaceableProofNotFactory()
- : SubTypeFactory()
- {}
- PlaceableProofNot* PlaceableProofNotFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- return new PlaceableProofNot(
- Game::INSTANCE->zTypeRegistry()->fromJson<PlaceableProof>(
- zJson->zValue("proof")));
- }
- Framework::JSON::JSONObject* PlaceableProofNotFactory::toJson(
- PlaceableProofNot* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "proof", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zProof()));
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- PlaceableProofNotFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder
- ->withRequiredAttribute("proof",
- Game::INSTANCE->zTypeRegistry()->getValidator<PlaceableProof>())
- ->finishObject();
- }
- Framework::Text PlaceableProofNotFactory::getTypeToken() const
- {
- return "not";
- }
- PlaceableProofBlockFilter::PlaceableProofBlockFilter(
- Direction direction, int distance, BlockFilter* filter)
- : PlaceableProof(),
- direction(direction),
- distance(distance),
- filter(filter)
- {}
- 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));
- }
- Direction PlaceableProofBlockFilter::getDirection() const
- {
- return direction;
- }
- int PlaceableProofBlockFilter::getDistance() const
- {
- return distance;
- }
- BlockFilter* PlaceableProofBlockFilter::zFilter() const
- {
- return filter;
- }
- PlaceableProofBlockFilterFactory::PlaceableProofBlockFilterFactory()
- : SubTypeFactory()
- {}
- PlaceableProofBlockFilter* PlaceableProofBlockFilterFactory::fromJson(
- 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;
- }
- return new PlaceableProofBlockFilter(dir,
- (int)zJson->zValue("distance")->asNumber()->getNumber(),
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->zValue("filter")));
- }
- Framework::JSON::JSONObject* PlaceableProofBlockFilterFactory::toJson(
- PlaceableProofBlockFilter* zObject) 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";
- }
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("direction", new Framework::JSON::JSONString(dir));
- result->addValue(
- "distance", new Framework::JSON::JSONNumber(zObject->getDistance()));
- result->addValue(
- "filter", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zFilter()));
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- PlaceableProofBlockFilterFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* 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>())
- ->finishObject();
- }
- Framework::Text PlaceableProofBlockFilterFactory::getTypeToken() const
- {
- return "blockFilter";
- }
|