mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Fix json value reader
This commit is contained in:
parent
30967b2813
commit
dfb078a4d9
@ -30,22 +30,26 @@ namespace JsonRandom
|
|||||||
{
|
{
|
||||||
si32 loadValue(const JsonNode & value, CRandomGenerator & rng, si32 defaultValue)
|
si32 loadValue(const JsonNode & value, CRandomGenerator & rng, si32 defaultValue)
|
||||||
{
|
{
|
||||||
if (value.isNull())
|
if(value.isNull())
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
if (value.isNumber())
|
if(value.isNumber())
|
||||||
return static_cast<si32>(value.Float());
|
return static_cast<si32>(value.Float());
|
||||||
if (value.isVector())
|
if(value.isVector())
|
||||||
{
|
{
|
||||||
const auto & vector = value.Vector();
|
const auto & vector = value.Vector();
|
||||||
|
|
||||||
size_t index= rng.getIntRange(0, vector.size()-1)();
|
size_t index= rng.getIntRange(0, vector.size()-1)();
|
||||||
return loadValue(vector[index], rng, 0);
|
return loadValue(vector[index], rng, 0);
|
||||||
}
|
}
|
||||||
if (!value["amount"].isNull())
|
if(value.isStruct())
|
||||||
return static_cast<si32>(loadValue(value["amount"], rng, defaultValue));
|
{
|
||||||
si32 min = static_cast<si32>(loadValue(value["min"], rng, 0));
|
if (!value["amount"].isNull())
|
||||||
si32 max = static_cast<si32>(loadValue(value["max"], rng, 0));
|
return static_cast<si32>(loadValue(value["amount"], rng, defaultValue));
|
||||||
return rng.getIntRange(min, max)();
|
si32 min = static_cast<si32>(loadValue(value["min"], rng, 0));
|
||||||
|
si32 max = static_cast<si32>(loadValue(value["max"], rng, 0));
|
||||||
|
return rng.getIntRange(min, max)();
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string loadKey(const JsonNode & value, CRandomGenerator & rng, const std::set<std::string> & valuesSet)
|
std::string loadKey(const JsonNode & value, CRandomGenerator & rng, const std::set<std::string> & valuesSet)
|
||||||
|
Loading…
Reference in New Issue
Block a user