From dfb078a4d9a139cfcb6d96e4feba5f80ba7d5b95 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Fri, 28 Apr 2023 05:12:54 +0400 Subject: [PATCH] Fix json value reader --- lib/JsonRandom.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/JsonRandom.cpp b/lib/JsonRandom.cpp index 827ed0bc3..4d107e605 100644 --- a/lib/JsonRandom.cpp +++ b/lib/JsonRandom.cpp @@ -30,22 +30,26 @@ namespace JsonRandom { si32 loadValue(const JsonNode & value, CRandomGenerator & rng, si32 defaultValue) { - if (value.isNull()) + if(value.isNull()) return defaultValue; - if (value.isNumber()) + if(value.isNumber()) return static_cast(value.Float()); - if (value.isVector()) + if(value.isVector()) { const auto & vector = value.Vector(); size_t index= rng.getIntRange(0, vector.size()-1)(); return loadValue(vector[index], rng, 0); } - if (!value["amount"].isNull()) - return static_cast(loadValue(value["amount"], rng, defaultValue)); - si32 min = static_cast(loadValue(value["min"], rng, 0)); - si32 max = static_cast(loadValue(value["max"], rng, 0)); - return rng.getIntRange(min, max)(); + if(value.isStruct()) + { + if (!value["amount"].isNull()) + return static_cast(loadValue(value["amount"], rng, defaultValue)); + si32 min = static_cast(loadValue(value["min"], rng, 0)); + si32 max = static_cast(loadValue(value["max"], rng, 0)); + return rng.getIntRange(min, max)(); + } + return defaultValue; } std::string loadKey(const JsonNode & value, CRandomGenerator & rng, const std::set & valuesSet)