123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- #include "BlockFilter.h"
- #include "Block.h"
- #include "FluidBlock.h"
- #include "Game.h"
- BlockFilter::BlockFilter()
- : ReferenceCounter()
- {}
- BlockFilterAnd::BlockFilterAnd()
- : BlockFilter()
- {}
- bool BlockFilterAnd::test(const Block* zBlock)
- {
- for (BlockFilter* filter : filters)
- {
- if (!filter->test(zBlock))
- {
- return false;
- }
- }
- return true;
- }
- void BlockFilterAnd::addFilter(BlockFilter* filter)
- {
- filters.add(filter);
- }
- Framework::RCArray<BlockFilter> BlockFilterAnd::getFilters() const
- {
- return filters;
- }
- BlockFilterAndFactory::BlockFilterAndFactory()
- : SubTypeFactory()
- {}
- BlockFilterAnd* BlockFilterAndFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterAnd();
- }
- void BlockFilterAndFactory::fromJson(
- BlockFilterAnd* zResult, Framework::JSON::JSONObject* zJson) const
- {
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("filters")->asArray())
- {
- zResult->addFilter(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(value));
- }
- }
- void BlockFilterAndFactory::toJson(
- BlockFilterAnd* zObject, Framework::JSON::JSONObject* zResult) const
- {
- Framework::JSON::JSONArray* filters = new Framework::JSON::JSONArray();
- for (BlockFilter* filter : zObject->getFilters())
- {
- filters->addValue(Game::INSTANCE->zTypeRegistry()->toJson(filter));
- }
- zResult->addValue("filters", filters);
- }
- JSONObjectValidationBuilder* BlockFilterAndFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredArray("filters")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
- ->finishArray();
- }
- Framework::Text BlockFilterAndFactory::getTypeToken() const
- {
- return "and";
- }
- BlockFilterOr::BlockFilterOr()
- : BlockFilter()
- {}
- bool BlockFilterOr::test(const Block* zBlock)
- {
- for (BlockFilter* filter : filters)
- {
- if (filter->test(zBlock))
- {
- return true;
- }
- }
- return false;
- }
- void BlockFilterOr::addFilter(BlockFilter* filter)
- {
- filters.add(filter);
- }
- Framework::RCArray<BlockFilter> BlockFilterOr::getFilters() const
- {
- return filters;
- }
- BlockFilterOrFactory::BlockFilterOrFactory()
- : SubTypeFactory()
- {}
- BlockFilterOr* BlockFilterOrFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterOr();
- }
- void BlockFilterOrFactory::fromJson(
- BlockFilterOr* zResult, Framework::JSON::JSONObject* zJson) const
- {
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("filters")->asArray())
- {
- zResult->addFilter(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(value));
- }
- }
- void BlockFilterOrFactory::toJson(
- BlockFilterOr* zObject, Framework::JSON::JSONObject* zResult) const
- {
- Framework::JSON::JSONArray* filters = new Framework::JSON::JSONArray();
- for (BlockFilter* filter : zObject->getFilters())
- {
- filters->addValue(Game::INSTANCE->zTypeRegistry()->toJson(filter));
- }
- zResult->addValue("filters", filters);
- }
- JSONObjectValidationBuilder* BlockFilterOrFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredArray("filters")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
- ->finishArray();
- }
- Framework::Text BlockFilterOrFactory::getTypeToken() const
- {
- return "or";
- }
- BlockFilterNot::BlockFilterNot()
- : BlockFilter(),
- filter(0)
- {}
- BlockFilterNot::~BlockFilterNot()
- {
- if (filter) filter->release();
- }
- bool BlockFilterNot::test(const Block* zBlock)
- {
- return !filter->test(zBlock);
- }
- void BlockFilterNot::setFilter(BlockFilter* filter)
- {
- if (this->filter) this->filter->release();
- this->filter = filter;
- }
- BlockFilter* BlockFilterNot::zFilter() const
- {
- return filter;
- }
- BlockFilterNotFactory::BlockFilterNotFactory()
- : SubTypeFactory()
- {}
- BlockFilterNot* BlockFilterNotFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterNot();
- }
- void BlockFilterNotFactory::fromJson(
- BlockFilterNot* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setFilter(Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->zValue("filter")));
- }
- void BlockFilterNotFactory::toJson(
- BlockFilterNot* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "filter", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zFilter()));
- }
- JSONObjectValidationBuilder* BlockFilterNotFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredAttribute(
- "filter", Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>());
- }
- Framework::Text BlockFilterNotFactory::getTypeToken() const
- {
- return "not";
- }
- BlockFilterBlockType::BlockFilterBlockType()
- : BlockFilter()
- {}
- bool BlockFilterBlockType::test(const Block* zBlock)
- {
- for (int blockTypeId : blockTypeIds)
- {
- if (zBlock->zBlockType()->getId() == blockTypeId)
- {
- return true;
- }
- }
- return false;
- }
- void BlockFilterBlockType::addBlockTypeId(int blockTypeId)
- {
- blockTypeIds.add(blockTypeId);
- }
- const Framework::Array<int>& BlockFilterBlockType::getBlockTypeIds() const
- {
- return blockTypeIds;
- }
- BlockFilterBlockTypeFactory::BlockFilterBlockTypeFactory()
- : SubTypeFactory()
- {}
- BlockFilterBlockType* BlockFilterBlockTypeFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterBlockType();
- }
- void BlockFilterBlockTypeFactory::fromJson(
- BlockFilterBlockType* zResult, Framework::JSON::JSONObject* zJson) const
- {
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("typeNames")->asArray())
- {
- zResult->addBlockTypeId(
- Game::INSTANCE->getBlockTypeId(value->asString()->getString()));
- }
- }
- void BlockFilterBlockTypeFactory::toJson(
- BlockFilterBlockType* zObject, Framework::JSON::JSONObject* zResult) const
- {
- Framework::JSON::JSONArray* typeNames = new Framework::JSON::JSONArray();
- for (int typeId : zObject->getBlockTypeIds())
- {
- typeNames->addValue(new Framework::JSON::JSONString(
- Game::INSTANCE->zBlockType(typeId)->getName()));
- }
- zResult->addValue("typeNames", typeNames);
- }
- JSONObjectValidationBuilder* BlockFilterBlockTypeFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredArray("typeNames")
- ->addAcceptedStringInArray()
- ->finishString()
- ->finishArray();
- }
- Framework::Text BlockFilterBlockTypeFactory::getTypeToken() const
- {
- return "types";
- }
- BlockFilterTypeGroup::BlockFilterTypeGroup()
- : BlockFilter()
- {}
- bool BlockFilterTypeGroup::test(const Block* zBlock)
- {
- for (Framework::Text* groupName : groupNames)
- {
- for (Framework::Text* otherGroupName :
- zBlock->zBlockType()->getGroupNames())
- {
- if (groupName->istGleich(*otherGroupName))
- {
- return true;
- }
- }
- }
- return false;
- }
- void BlockFilterTypeGroup::addGroupName(const Framework::Text groupName)
- {
- groupNames.add(new Framework::Text(groupName));
- }
- const Framework::RCArray<Framework::Text>&
- BlockFilterTypeGroup::getGroupNames() const
- {
- return groupNames;
- }
- BlockFilterTypeGroupFactory::BlockFilterTypeGroupFactory()
- : SubTypeFactory()
- {}
- BlockFilterTypeGroup* BlockFilterTypeGroupFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterTypeGroup();
- }
- void BlockFilterTypeGroupFactory::fromJson(
- BlockFilterTypeGroup* zResult, Framework::JSON::JSONObject* zJson) const
- {
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("groupNames")->asArray())
- {
- zResult->addGroupName(value->asString()->getString());
- }
- }
- void BlockFilterTypeGroupFactory::toJson(
- BlockFilterTypeGroup* zObject, Framework::JSON::JSONObject* zResult) const
- {
- Framework::JSON::JSONArray* groupNames = new Framework::JSON::JSONArray();
- for (Framework::Text* groupName : zObject->getGroupNames())
- {
- groupNames->addValue(new Framework::JSON::JSONString(*groupName));
- }
- zResult->addValue("groupNames", groupNames);
- }
- JSONObjectValidationBuilder* BlockFilterTypeGroupFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredArray("groupNames")
- ->addAcceptedStringInArray()
- ->finishString()
- ->finishArray();
- }
- Framework::Text BlockFilterTypeGroupFactory::getTypeToken() const
- {
- return "groups";
- }
- BlockFilterMaxHardness::BlockFilterMaxHardness()
- : BlockFilter()
- {}
- bool BlockFilterMaxHardness::test(const Block* zBlock)
- {
- return zBlock->zBlockType()->getHardness() <= maxHardness;
- }
- void BlockFilterMaxHardness::setMaxHardness(float maxHardness)
- {
- this->maxHardness = maxHardness;
- }
- float BlockFilterMaxHardness::getMaxHardness() const
- {
- return maxHardness;
- }
- BlockFilterMaxHardnessFactory::BlockFilterMaxHardnessFactory()
- : SubTypeFactory()
- {}
- BlockFilterMaxHardness* BlockFilterMaxHardnessFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterMaxHardness();
- }
- void BlockFilterMaxHardnessFactory::fromJson(
- BlockFilterMaxHardness* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setMaxHardness(
- (float)zJson->zValue("maxHardness")->asNumber()->getNumber());
- }
- void BlockFilterMaxHardnessFactory::toJson(
- BlockFilterMaxHardness* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("maxHardness",
- new Framework::JSON::JSONNumber(zObject->getMaxHardness()));
- }
- JSONObjectValidationBuilder* BlockFilterMaxHardnessFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredNumber("maxHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber();
- }
- Framework::Text BlockFilterMaxHardnessFactory::getTypeToken() const
- {
- return "maxHardness";
- }
- BlockFilterMinHardness::BlockFilterMinHardness()
- : BlockFilter(),
- minHardness(0.f)
- {}
- bool BlockFilterMinHardness::test(const Block* zBlock)
- {
- return zBlock->zBlockType()->getHardness() >= minHardness;
- }
- void BlockFilterMinHardness::setMinHardness(float minHardness)
- {
- this->minHardness = minHardness;
- }
- float BlockFilterMinHardness::getMinHardness() const
- {
- return minHardness;
- }
- BlockFilterMinHardnessFactory::BlockFilterMinHardnessFactory()
- : SubTypeFactory()
- {}
- BlockFilterMinHardness* BlockFilterMinHardnessFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterMinHardness();
- }
- void BlockFilterMinHardnessFactory::fromJson(
- BlockFilterMinHardness* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setMinHardness(
- (float)zJson->zValue("minHardness")->asNumber()->getNumber());
- }
- void BlockFilterMinHardnessFactory::toJson(
- BlockFilterMinHardness* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("minHardness",
- new Framework::JSON::JSONNumber(zObject->getMinHardness()));
- }
- JSONObjectValidationBuilder* BlockFilterMinHardnessFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredNumber("minHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber();
- }
- Framework::Text BlockFilterMinHardnessFactory::getTypeToken() const
- {
- return "minHardness";
- }
- BlockFilterMaxHeat::BlockFilterMaxHeat()
- : BlockFilter(),
- maxHeat(0.f)
- {}
- bool BlockFilterMaxHeat::test(const Block* zBlock)
- {
- const FluidBlockType* type
- = dynamic_cast<const FluidBlockType*>(zBlock->zBlockType());
- return type && type->getHeat() <= maxHeat;
- }
- void BlockFilterMaxHeat::setMaxHeat(float maxHeat)
- {
- this->maxHeat = maxHeat;
- }
- float BlockFilterMaxHeat::getMaxHeat() const
- {
- return maxHeat;
- }
- BlockFilterMaxHeatFactory::BlockFilterMaxHeatFactory()
- : SubTypeFactory()
- {}
- BlockFilterMaxHeat* BlockFilterMaxHeatFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockFilterMaxHeat();
- }
- void BlockFilterMaxHeatFactory::fromJson(
- BlockFilterMaxHeat* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setMaxHeat((float)zJson->zValue("heat")->asNumber()->getNumber());
- }
- void BlockFilterMaxHeatFactory::toJson(
- BlockFilterMaxHeat* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "heat", new Framework::JSON::JSONNumber(zObject->getMaxHeat()));
- }
- JSONObjectValidationBuilder* BlockFilterMaxHeatFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredNumber("heat")->finishNumber();
- }
- Framework::Text BlockFilterMaxHeatFactory::getTypeToken() const
- {
- return "maxHeat";
- }
|