|
@@ -152,15 +152,52 @@ void RecipieLoader::loadRecipie(JSONObject* zRecipie)
|
|
|
|
|
|
ItemFilter* RecipieLoader::loadFilter(JSONObject* zFilter)
|
|
|
{
|
|
|
- Framework::Text type = zFilter->zValue("itemType")->asString()->getString();
|
|
|
- for (int i = 0; i < StaticRegistry<ItemType>::INSTANCE.getCount(); i++)
|
|
|
+ if (zFilter->hasValue("itemType"))
|
|
|
{
|
|
|
- if (StaticRegistry<ItemType>::INSTANCE.zElement(i)
|
|
|
- && StaticRegistry<ItemType>::INSTANCE.zElement(i)
|
|
|
- ->getName()
|
|
|
- .istGleich(type))
|
|
|
- return new TypeItemFilter(
|
|
|
- StaticRegistry<ItemType>::INSTANCE.zElement(i));
|
|
|
+ Framework::Text type
|
|
|
+ = zFilter->zValue("itemType")->asString()->getString();
|
|
|
+ for (int i = 0; i < StaticRegistry<ItemType>::INSTANCE.getCount(); i++)
|
|
|
+ {
|
|
|
+ if (StaticRegistry<ItemType>::INSTANCE.zElement(i)
|
|
|
+ && StaticRegistry<ItemType>::INSTANCE.zElement(i)
|
|
|
+ ->getName()
|
|
|
+ .istGleich(type))
|
|
|
+ return new TypeItemFilter(
|
|
|
+ StaticRegistry<ItemType>::INSTANCE.zElement(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (zFilter->hasValue("operator"))
|
|
|
+ {
|
|
|
+ Framework::Text op = zFilter->zValue("operator")
|
|
|
+ ->asString()
|
|
|
+ ->getString();
|
|
|
+ ItemFilter* left = loadFilter(zFilter->zValue("left")->asObject());
|
|
|
+ ItemFilter* right = loadFilter(zFilter->zValue("right")->asObject());
|
|
|
+ if (op.istGleich("&&"))
|
|
|
+ {
|
|
|
+ return new CombinedItemFilter(
|
|
|
+ left, right, [](bool a, bool b) { return a && b; });
|
|
|
+ }
|
|
|
+ else if (op.istGleich("||"))
|
|
|
+ {
|
|
|
+ return new CombinedItemFilter(
|
|
|
+ left, right, [](bool a, bool b) { return a || b; });
|
|
|
+ }
|
|
|
+ else if (op.istGleich("=="))
|
|
|
+ {
|
|
|
+ return new CombinedItemFilter(
|
|
|
+ left, right, [](bool a, bool b) { return a == b; });
|
|
|
+ }
|
|
|
+ else if (op.istGleich("!="))
|
|
|
+ {
|
|
|
+ return new CombinedItemFilter(
|
|
|
+ left, right, [](bool a, bool b) { return a != b; });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ left->release();
|
|
|
+ right->release();
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
@@ -233,11 +270,33 @@ JSONValidator* RecipieLoader::zRecipieValidator()
|
|
|
.getText()));
|
|
|
}
|
|
|
}
|
|
|
- JSONValidator* filterValidator = JSONValidator::buildForObject()
|
|
|
- ->withRequiredString("itemType")
|
|
|
- ->whichIsOneOf(itemTypes)
|
|
|
- ->finishString()
|
|
|
- ->finishObject();
|
|
|
+ JSONValidator* typeFilterValidator
|
|
|
+ = JSONValidator::buildForObject()
|
|
|
+ ->setObjectReferenceId("typeFilter")
|
|
|
+ ->withRequiredString("itemType")
|
|
|
+ ->whichIsOneOf(itemTypes)
|
|
|
+ ->finishString()
|
|
|
+ ->finishObject();
|
|
|
+ Framework::RCArray<Framework::Text> operators;
|
|
|
+ operators.add(new Framework::Text("=="));
|
|
|
+ operators.add(new Framework::Text("!="));
|
|
|
+ operators.add(new Framework::Text("&&"));
|
|
|
+ operators.add(new Framework::Text("||"));
|
|
|
+ JSONValidator* operatorFilterValidator
|
|
|
+ = JSONValidator::buildForObject()
|
|
|
+ ->setObjectReferenceId("operatorFilter")
|
|
|
+ ->withRequiredString("operator")
|
|
|
+ ->whichIsOneOf(operators)
|
|
|
+ ->finishString()
|
|
|
+ ->withRequiredAttribute(
|
|
|
+ "left", JSONValidator::buildForObjectReference("typeFilter"))
|
|
|
+ ->withRequiredAttribute("left",
|
|
|
+ JSONValidator::buildForObjectReference("operatorFilter"))
|
|
|
+ ->withRequiredAttribute(
|
|
|
+ "right", JSONValidator::buildForObjectReference("typeFilter"))
|
|
|
+ ->withRequiredAttribute("right",
|
|
|
+ JSONValidator::buildForObjectReference("operatorFilter"))
|
|
|
+ ->finishObject();
|
|
|
JSONValidator* outputValidator = JSONValidator::buildForObject()
|
|
|
->withRequiredString("itemType")
|
|
|
->whichIsOneOf(itemTypes)
|
|
@@ -273,7 +332,11 @@ JSONValidator* RecipieLoader::zRecipieValidator()
|
|
|
->finishNumber()
|
|
|
->withRequiredAttribute("filter",
|
|
|
dynamic_cast<JSONValidator*>(
|
|
|
- filterValidator->getThis()))
|
|
|
+ typeFilterValidator->getThis()))
|
|
|
+ ->withRequiredAttribute("filter",
|
|
|
+ dynamic_cast<JSONValidator*>(
|
|
|
+ operatorFilterValidator
|
|
|
+ ->getThis()))
|
|
|
->withRequiredAttribute("modifiers",
|
|
|
JSONValidator::buildForArray()
|
|
|
->withDefault(Parser::getValue(
|
|
@@ -319,7 +382,11 @@ JSONValidator* RecipieLoader::zRecipieValidator()
|
|
|
->finishNumber()
|
|
|
->withRequiredAttribute("filter",
|
|
|
dynamic_cast<JSONValidator*>(
|
|
|
- filterValidator->getThis()))
|
|
|
+ typeFilterValidator->getThis()))
|
|
|
+ ->withRequiredAttribute("filter",
|
|
|
+ dynamic_cast<JSONValidator*>(
|
|
|
+ operatorFilterValidator
|
|
|
+ ->getThis()))
|
|
|
->withRequiredAttribute("modifiers",
|
|
|
JSONValidator::buildForArray()
|
|
|
->withDefault(Parser::getValue(
|
|
@@ -354,7 +421,8 @@ JSONValidator* RecipieLoader::zRecipieValidator()
|
|
|
->finishArray())
|
|
|
->finishObject())
|
|
|
->finishArray();
|
|
|
- filterValidator->release();
|
|
|
+ typeFilterValidator->release();
|
|
|
+ operatorFilterValidator->release();
|
|
|
outputValidator->release();
|
|
|
return validator;
|
|
|
}
|