mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Little code improvement
This commit is contained in:
@@ -48,22 +48,28 @@ namespace JsonRandom
|
|||||||
return rng.getIntRange(min, max)();
|
return rng.getIntRange(min, max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string loadKey(const JsonNode & value, CRandomGenerator & rng, std::set<std::string> valuesSet)
|
std::string loadKey(const JsonNode & value, CRandomGenerator & rng, const std::set<std::string> & valuesSet)
|
||||||
{
|
{
|
||||||
if (value.isNull())
|
if(value.isString())
|
||||||
return valuesSet.empty() ? "" : *RandomGeneratorUtil::nextItem(valuesSet, rng);
|
|
||||||
if (value.isString())
|
|
||||||
return value.String();
|
return value.String();
|
||||||
if (!value["type"].isNull())
|
|
||||||
return value["type"].String();
|
|
||||||
|
|
||||||
if(!value["anyOf"].isNull())
|
if(value.isStruct())
|
||||||
return RandomGeneratorUtil::nextItem(value["anyOf"].Vector(), rng)->String();
|
|
||||||
|
|
||||||
if(!value["noneOf"].isNull())
|
|
||||||
{
|
{
|
||||||
for(auto & s : value["noneOf"].Vector())
|
if(!value["type"].isNull())
|
||||||
valuesSet.erase(s.String());
|
return value["type"].String();
|
||||||
|
|
||||||
|
if(!value["anyOf"].isNull())
|
||||||
|
return RandomGeneratorUtil::nextItem(value["anyOf"].Vector(), rng)->String();
|
||||||
|
|
||||||
|
if(!value["noneOf"].isNull())
|
||||||
|
{
|
||||||
|
auto copyValuesSet = valuesSet;
|
||||||
|
for(auto & s : value["noneOf"].Vector())
|
||||||
|
copyValuesSet.erase(s.String());
|
||||||
|
|
||||||
|
if(!copyValuesSet.empty())
|
||||||
|
return *RandomGeneratorUtil::nextItem(copyValuesSet, rng);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valuesSet.empty() ? "" : *RandomGeneratorUtil::nextItem(valuesSet, rng);
|
return valuesSet.empty() ? "" : *RandomGeneratorUtil::nextItem(valuesSet, rng);
|
||||||
|
Reference in New Issue
Block a user