mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Extend loadKey function
This commit is contained in:
@@ -46,26 +46,27 @@ namespace JsonRandom
|
|||||||
return rng.getIntRange(min, max)();
|
return rng.getIntRange(min, max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_LINKAGE std::string loadKey(const JsonNode & value, CRandomGenerator & rng, std::string defaultValue)
|
std::string loadKey(const JsonNode & value, CRandomGenerator & rng, std::set<std::string> valuesSet)
|
||||||
{
|
{
|
||||||
if (value.isNull())
|
if (value.isNull())
|
||||||
return defaultValue;
|
return valuesSet.empty() ? "" : *RandomGeneratorUtil::nextItem(valuesSet, rng);
|
||||||
if (value.isString())
|
if (value.isString())
|
||||||
return value.String();
|
return value.String();
|
||||||
if (!value["type"].isNull())
|
if (!value["type"].isNull())
|
||||||
return value["type"].String();
|
return value["type"].String();
|
||||||
|
|
||||||
if (value["list"].isNull())
|
if(!value["list"].isNull())
|
||||||
return defaultValue;
|
{
|
||||||
|
return RandomGeneratorUtil::nextItem(value["list"].Vector(), rng)->String();
|
||||||
|
}
|
||||||
|
|
||||||
const auto & resourceList = value["list"].Vector();
|
if(!value["except"].isNull())
|
||||||
|
{
|
||||||
|
for(auto & s : value["except"].Vector())
|
||||||
|
valuesSet.erase(s.String());
|
||||||
|
}
|
||||||
|
|
||||||
if (resourceList.empty())
|
return valuesSet.empty() ? "" : *RandomGeneratorUtil::nextItem(valuesSet, rng);
|
||||||
return defaultValue;
|
|
||||||
|
|
||||||
si32 index = rng.getIntRange(0, resourceList.size() - 1 )();
|
|
||||||
|
|
||||||
return resourceList[index].String();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TResources loadResources(const JsonNode & value, CRandomGenerator & rng)
|
TResources loadResources(const JsonNode & value, CRandomGenerator & rng)
|
||||||
|
Reference in New Issue
Block a user