mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Cleanup
This commit is contained in:
parent
18bbccd167
commit
29860848a5
@ -350,8 +350,7 @@ std::vector<JsonNode> CArtHandler::loadLegacyData()
|
|||||||
{
|
{
|
||||||
if(parser.readString() == "x")
|
if(parser.readString() == "x")
|
||||||
{
|
{
|
||||||
artData["slot"].Vector().push_back(JsonNode());
|
artData["slot"].Vector().emplace_back(artSlot);
|
||||||
artData["slot"].Vector().back().String() = artSlot;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
artData["class"].String() = classes.at(parser.readString()[0]);
|
artData["class"].String() = classes.at(parser.readString()[0]);
|
||||||
|
@ -13,23 +13,17 @@
|
|||||||
|
|
||||||
#include "JsonValidator.h"
|
#include "JsonValidator.h"
|
||||||
|
|
||||||
#include "../ScopeGuard.h"
|
#include "../CGeneralTextHandler.h"
|
||||||
|
#include "../VCMI_Lib.h"
|
||||||
#include "../bonuses/BonusParams.h"
|
#include "../bonuses/BonusParams.h"
|
||||||
#include "../bonuses/Bonus.h"
|
|
||||||
#include "../bonuses/Limiters.h"
|
#include "../bonuses/Limiters.h"
|
||||||
#include "../bonuses/Propagators.h"
|
#include "../bonuses/Propagators.h"
|
||||||
#include "../bonuses/Updaters.h"
|
#include "../bonuses/Updaters.h"
|
||||||
#include "../filesystem/Filesystem.h"
|
|
||||||
#include "../modding/IdentifierStorage.h"
|
|
||||||
#include "../VCMI_Lib.h" //for identifier resolution
|
|
||||||
#include "../CGeneralTextHandler.h"
|
|
||||||
#include "../constants/StringConstants.h"
|
#include "../constants/StringConstants.h"
|
||||||
#include "../battle/BattleHex.h"
|
#include "../modding/IdentifierStorage.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
static const JsonNode nullNode;
|
|
||||||
|
|
||||||
static void loadBonusSubtype(BonusSubtypeID & subtype, BonusType type, const JsonNode & node)
|
static void loadBonusSubtype(BonusSubtypeID & subtype, BonusType type, const JsonNode & node)
|
||||||
{
|
{
|
||||||
if (node.isNull())
|
if (node.isNull())
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
#include "JsonWriter.h"
|
#include "JsonWriter.h"
|
||||||
#include "filesystem/Filesystem.h"
|
#include "filesystem/Filesystem.h"
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// to avoid duplicating const and non-const code
|
// to avoid duplicating const and non-const code
|
||||||
template<typename Node>
|
template<typename Node>
|
||||||
Node & resolvePointer(Node & in, const std::string & pointer)
|
Node & resolvePointer(Node & in, const std::string & pointer)
|
||||||
@ -45,15 +43,14 @@ Node & resolvePointer(Node & in, const std::string & pointer)
|
|||||||
}
|
}
|
||||||
return in[entry].resolvePointer(remainer);
|
return in[entry].resolvePointer(remainer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
static const JsonNode nullNode;
|
||||||
|
|
||||||
class LibClasses;
|
class LibClasses;
|
||||||
class CModHandler;
|
class CModHandler;
|
||||||
|
|
||||||
static const JsonNode nullNode;
|
|
||||||
|
|
||||||
JsonNode::JsonNode(bool boolean)
|
JsonNode::JsonNode(bool boolean)
|
||||||
: data(boolean)
|
: data(boolean)
|
||||||
{
|
{
|
||||||
@ -91,15 +88,20 @@ JsonNode::JsonNode(const std::byte * data, size_t datasize)
|
|||||||
|
|
||||||
JsonNode::JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings)
|
JsonNode::JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings)
|
||||||
{
|
{
|
||||||
JsonParser parser(reinterpret_cast<const char *>(data), datasize, parserSettings);
|
JsonParser parser(data, datasize, parserSettings);
|
||||||
*this = parser.parse("<unknown>");
|
*this = parser.parse("<unknown>");
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode::JsonNode(const JsonPath & fileURI)
|
JsonNode::JsonNode(const JsonPath & fileURI)
|
||||||
|
:JsonNode(fileURI, JsonParsingSettings())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonNode::JsonNode(const JsonPath & fileURI, const JsonParsingSettings & parserSettings)
|
||||||
{
|
{
|
||||||
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||||
|
|
||||||
JsonParser parser(reinterpret_cast<char *>(file.first.get()), file.second, JsonParsingSettings());
|
JsonParser parser(reinterpret_cast<std::byte *>(file.first.get()), file.second, parserSettings);
|
||||||
*this = parser.parse(fileURI.getName());
|
*this = parser.parse(fileURI.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ JsonNode::JsonNode(const JsonPath & fileURI, const std::string & idx)
|
|||||||
{
|
{
|
||||||
auto file = CResourceHandler::get(idx)->load(fileURI)->readAll();
|
auto file = CResourceHandler::get(idx)->load(fileURI)->readAll();
|
||||||
|
|
||||||
JsonParser parser(reinterpret_cast<char *>(file.first.get()), file.second, JsonParsingSettings());
|
JsonParser parser(reinterpret_cast<std::byte *>(file.first.get()), file.second, JsonParsingSettings());
|
||||||
*this = parser.parse(fileURI.getName());
|
*this = parser.parse(fileURI.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +117,7 @@ JsonNode::JsonNode(const JsonPath & fileURI, bool & isValidSyntax)
|
|||||||
{
|
{
|
||||||
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||||
|
|
||||||
JsonParser parser(reinterpret_cast<char *>(file.first.get()), file.second, JsonParsingSettings());
|
JsonParser parser(reinterpret_cast<std::byte *>(file.first.get()), file.second, JsonParsingSettings());
|
||||||
*this = parser.parse(fileURI.getName());
|
*this = parser.parse(fileURI.getName());
|
||||||
isValidSyntax = parser.isValid();
|
isValidSyntax = parser.isValid();
|
||||||
}
|
}
|
||||||
@ -206,7 +208,7 @@ void JsonNode::setType(JsonType Type)
|
|||||||
data = JsonData(false);
|
data = JsonData(false);
|
||||||
break;
|
break;
|
||||||
case JsonType::DATA_FLOAT:
|
case JsonType::DATA_FLOAT:
|
||||||
data = JsonData(static_cast<double>(0.0));
|
data = JsonData(0.0);
|
||||||
break;
|
break;
|
||||||
case JsonType::DATA_STRING:
|
case JsonType::DATA_STRING:
|
||||||
data = JsonData(std::string());
|
data = JsonData(std::string());
|
||||||
@ -355,9 +357,10 @@ JsonMap & JsonNode::Struct()
|
|||||||
return std::get<JsonMap>(data);
|
return std::get<JsonMap>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool boolDefault = false;
|
|
||||||
bool JsonNode::Bool() const
|
bool JsonNode::Bool() const
|
||||||
{
|
{
|
||||||
|
static const bool boolDefault = false;
|
||||||
|
|
||||||
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_BOOL);
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_BOOL);
|
||||||
|
|
||||||
if(getType() == JsonType::DATA_BOOL)
|
if(getType() == JsonType::DATA_BOOL)
|
||||||
@ -366,9 +369,10 @@ bool JsonNode::Bool() const
|
|||||||
return boolDefault;
|
return boolDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
const double floatDefault = 0;
|
|
||||||
double JsonNode::Float() const
|
double JsonNode::Float() const
|
||||||
{
|
{
|
||||||
|
static const double floatDefault = 0;
|
||||||
|
|
||||||
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT);
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT);
|
||||||
|
|
||||||
if(getType() == JsonType::DATA_FLOAT)
|
if(getType() == JsonType::DATA_FLOAT)
|
||||||
@ -380,9 +384,10 @@ double JsonNode::Float() const
|
|||||||
return floatDefault;
|
return floatDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
const si64 integerDefault = 0;
|
|
||||||
si64 JsonNode::Integer() const
|
si64 JsonNode::Integer() const
|
||||||
{
|
{
|
||||||
|
static const si64 integerDefault = 0;
|
||||||
|
|
||||||
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT);
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT);
|
||||||
|
|
||||||
if(getType() == JsonType::DATA_INTEGER)
|
if(getType() == JsonType::DATA_INTEGER)
|
||||||
@ -394,9 +399,10 @@ si64 JsonNode::Integer() const
|
|||||||
return integerDefault;
|
return integerDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string stringDefault = std::string();
|
|
||||||
const std::string & JsonNode::String() const
|
const std::string & JsonNode::String() const
|
||||||
{
|
{
|
||||||
|
static const std::string stringDefault = std::string();
|
||||||
|
|
||||||
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_STRING);
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_STRING);
|
||||||
|
|
||||||
if(getType() == JsonType::DATA_STRING)
|
if(getType() == JsonType::DATA_STRING)
|
||||||
@ -405,9 +411,10 @@ const std::string & JsonNode::String() const
|
|||||||
return stringDefault;
|
return stringDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonVector vectorDefault = JsonVector();
|
|
||||||
const JsonVector & JsonNode::Vector() const
|
const JsonVector & JsonNode::Vector() const
|
||||||
{
|
{
|
||||||
|
static const JsonVector vectorDefault = JsonVector();
|
||||||
|
|
||||||
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_VECTOR);
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_VECTOR);
|
||||||
|
|
||||||
if(getType() == JsonType::DATA_VECTOR)
|
if(getType() == JsonType::DATA_VECTOR)
|
||||||
@ -416,9 +423,10 @@ const JsonVector & JsonNode::Vector() const
|
|||||||
return vectorDefault;
|
return vectorDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonMap mapDefault = JsonMap();
|
|
||||||
const JsonMap & JsonNode::Struct() const
|
const JsonMap & JsonNode::Struct() const
|
||||||
{
|
{
|
||||||
|
static const JsonMap mapDefault = JsonMap();
|
||||||
|
|
||||||
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_STRUCT);
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_STRUCT);
|
||||||
|
|
||||||
if(getType() == JsonType::DATA_STRUCT)
|
if(getType() == JsonType::DATA_STRUCT)
|
||||||
|
@ -76,6 +76,7 @@ public:
|
|||||||
|
|
||||||
/// Create tree from JSON file
|
/// Create tree from JSON file
|
||||||
explicit JsonNode(const JsonPath & fileURI);
|
explicit JsonNode(const JsonPath & fileURI);
|
||||||
|
explicit JsonNode(const JsonPath & fileURI, const JsonParsingSettings & parserSettings);
|
||||||
explicit JsonNode(const JsonPath & fileURI, const std::string & modName);
|
explicit JsonNode(const JsonPath & fileURI, const std::string & modName);
|
||||||
explicit JsonNode(const JsonPath & fileURI, bool & isValidSyntax);
|
explicit JsonNode(const JsonPath & fileURI, bool & isValidSyntax);
|
||||||
|
|
||||||
|
@ -11,16 +11,17 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "JsonParser.h"
|
#include "JsonParser.h"
|
||||||
|
|
||||||
|
#include "../ScopeGuard.h"
|
||||||
#include "../TextOperations.h"
|
#include "../TextOperations.h"
|
||||||
#include "JsonFormatException.h"
|
#include "JsonFormatException.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
JsonParser::JsonParser(const char * inputString, size_t stringSize, const JsonParsingSettings & settings)
|
JsonParser::JsonParser(const std::byte * inputString, size_t stringSize, const JsonParsingSettings & settings)
|
||||||
: input(inputString, stringSize)
|
: settings(settings)
|
||||||
, settings(settings)
|
, input(reinterpret_cast<const char *>(inputString), stringSize)
|
||||||
, currentDepth(0)
|
|
||||||
, lineCount(1)
|
, lineCount(1)
|
||||||
|
, currentDepth(0)
|
||||||
, lineStart(0)
|
, lineStart(0)
|
||||||
, pos(0)
|
, pos(0)
|
||||||
{
|
{
|
||||||
@ -258,7 +259,6 @@ bool JsonParser::extractLiteral(std::string & literal)
|
|||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += literal.size();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,10 +309,14 @@ bool JsonParser::extractStruct(JsonNode & node)
|
|||||||
node.setType(JsonNode::JsonType::DATA_STRUCT);
|
node.setType(JsonNode::JsonType::DATA_STRUCT);
|
||||||
|
|
||||||
if(currentDepth > settings.maxDepth)
|
if(currentDepth > settings.maxDepth)
|
||||||
error("Macimum allowed depth of json structure has been reached", true);
|
error("Maximum allowed depth of json structure has been reached", true);
|
||||||
|
|
||||||
currentDepth++;
|
|
||||||
pos++;
|
pos++;
|
||||||
|
currentDepth++;
|
||||||
|
auto guard = vstd::makeScopeGuard([this]()
|
||||||
|
{
|
||||||
|
currentDepth--;
|
||||||
|
});
|
||||||
|
|
||||||
if(!extractWhitespace())
|
if(!extractWhitespace())
|
||||||
return false;
|
return false;
|
||||||
@ -393,6 +397,11 @@ bool JsonParser::extractArray(JsonNode & node)
|
|||||||
error("Macimum allowed depth of json structure has been reached", true);
|
error("Macimum allowed depth of json structure has been reached", true);
|
||||||
|
|
||||||
currentDepth++;
|
currentDepth++;
|
||||||
|
auto guard = vstd::makeScopeGuard([this]()
|
||||||
|
{
|
||||||
|
currentDepth--;
|
||||||
|
});
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
node.setType(JsonNode::JsonType::DATA_VECTOR);
|
node.setType(JsonNode::JsonType::DATA_VECTOR);
|
||||||
|
|
||||||
@ -441,11 +450,9 @@ bool JsonParser::extractElement(JsonNode & node, char terminator)
|
|||||||
|
|
||||||
if(input[pos] == terminator)
|
if(input[pos] == terminator)
|
||||||
{
|
{
|
||||||
if(comma)
|
if(comma && settings.mode < JsonParsingSettings::JsonFormatMode::JSON5)
|
||||||
{
|
error("Extra comma found!", true);
|
||||||
if(settings.mode < JsonParsingSettings::JsonFormatMode::JSON5)
|
|
||||||
error("Extra comma found!", true);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,11 +507,8 @@ bool JsonParser::extractFloat(JsonNode & node)
|
|||||||
pos++;
|
pos++;
|
||||||
double fractMult = 0.1;
|
double fractMult = 0.1;
|
||||||
|
|
||||||
if(settings.mode < JsonParsingSettings::JsonFormatMode::JSON5)
|
if(settings.mode < JsonParsingSettings::JsonFormatMode::JSON5 && (input[pos] < '0' || input[pos] > '9'))
|
||||||
{
|
return error("Decimal part expected!");
|
||||||
if(input[pos] < '0' || input[pos] > '9')
|
|
||||||
return error("Decimal part expected!");
|
|
||||||
}
|
|
||||||
|
|
||||||
while(input[pos] >= '0' && input[pos] <= '9')
|
while(input[pos] >= '0' && input[pos] <= '9')
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ class JsonParser
|
|||||||
bool error(const std::string & message, bool warning = false);
|
bool error(const std::string & message, bool warning = false);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JsonParser(const char * inputString, size_t stringSize, const JsonParsingSettings & settings);
|
JsonParser(const std::byte * inputString, size_t stringSize, const JsonParsingSettings & settings);
|
||||||
|
|
||||||
/// do actual parsing. filename is name of file that will printed to console if any errors were found
|
/// do actual parsing. filename is name of file that will printed to console if any errors were found
|
||||||
JsonNode parse(const std::string & fileName);
|
JsonNode parse(const std::string & fileName);
|
||||||
|
@ -235,9 +235,9 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
filteredAnyOf.insert(subset.begin(), subset.end());
|
filteredAnyOf.insert(subset.begin(), subset.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
vstd::erase_if(filteredTypes, [&](const IdentifierType & value)
|
vstd::erase_if(filteredTypes, [&filteredAnyOf](const IdentifierType & filteredValue)
|
||||||
{
|
{
|
||||||
return filteredAnyOf.count(value) == 0;
|
return filteredAnyOf.count(filteredValue) == 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,18 +13,7 @@
|
|||||||
|
|
||||||
#include "JsonValidator.h"
|
#include "JsonValidator.h"
|
||||||
|
|
||||||
#include "../ScopeGuard.h"
|
|
||||||
#include "../bonuses/BonusParams.h"
|
|
||||||
#include "../bonuses/Bonus.h"
|
|
||||||
#include "../bonuses/Limiters.h"
|
|
||||||
#include "../bonuses/Propagators.h"
|
|
||||||
#include "../bonuses/Updaters.h"
|
|
||||||
#include "../filesystem/Filesystem.h"
|
#include "../filesystem/Filesystem.h"
|
||||||
#include "../modding/IdentifierStorage.h"
|
|
||||||
#include "../VCMI_Lib.h" //for identifier resolution
|
|
||||||
#include "../CGeneralTextHandler.h"
|
|
||||||
#include "../constants/StringConstants.h"
|
|
||||||
#include "../battle/BattleHex.h"
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ namespace
|
|||||||
|
|
||||||
std::string allOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
std::string allOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||||
{
|
{
|
||||||
return schemaListCheck(validator, baseSchema, schema, data, "Failed to pass all schemas", [&](size_t count)
|
return schemaListCheck(validator, baseSchema, schema, data, "Failed to pass all schemas", [&schema](size_t count)
|
||||||
{
|
{
|
||||||
return count == schema.Vector().size();
|
return count == schema.Vector().size();
|
||||||
});
|
});
|
||||||
@ -89,7 +89,7 @@ namespace
|
|||||||
|
|
||||||
std::string anyOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
std::string anyOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||||
{
|
{
|
||||||
return schemaListCheck(validator, baseSchema, schema, data, "Failed to pass any schema", [&](size_t count)
|
return schemaListCheck(validator, baseSchema, schema, data, "Failed to pass any schema", [](size_t count)
|
||||||
{
|
{
|
||||||
return count > 0;
|
return count > 0;
|
||||||
});
|
});
|
||||||
@ -97,7 +97,7 @@ namespace
|
|||||||
|
|
||||||
std::string oneOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
std::string oneOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||||
{
|
{
|
||||||
return schemaListCheck(validator, baseSchema, schema, data, "Failed to pass exactly one schema", [&](size_t count)
|
return schemaListCheck(validator, baseSchema, schema, data, "Failed to pass exactly one schema", [](size_t count)
|
||||||
{
|
{
|
||||||
return count == 1;
|
return count == 1;
|
||||||
});
|
});
|
||||||
@ -228,7 +228,7 @@ namespace
|
|||||||
|
|
||||||
std::string multipleOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
std::string multipleOfCheck(Validation::ValidationData & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||||
{
|
{
|
||||||
double result = data.Float() / schema.Float();
|
double result = data.Integer() / schema.Integer();
|
||||||
if (!vstd::isAlmostEqual(floor(result), result))
|
if (!vstd::isAlmostEqual(floor(result), result))
|
||||||
return validator.makeErrorMessage((boost::format("Value is not divisible by %d") % schema.Float()).str());
|
return validator.makeErrorMessage((boost::format("Value is not divisible by %d") % schema.Float()).str());
|
||||||
return "";
|
return "";
|
||||||
@ -241,7 +241,7 @@ namespace
|
|||||||
{
|
{
|
||||||
validator.currentPath.emplace_back();
|
validator.currentPath.emplace_back();
|
||||||
validator.currentPath.back().Float() = static_cast<double>(index);
|
validator.currentPath.back().Float() = static_cast<double>(index);
|
||||||
auto onExit = vstd::makeScopeGuard([&]()
|
auto onExit = vstd::makeScopeGuard([&validator]()
|
||||||
{
|
{
|
||||||
validator.currentPath.pop_back();
|
validator.currentPath.pop_back();
|
||||||
});
|
});
|
||||||
@ -390,7 +390,7 @@ namespace
|
|||||||
{
|
{
|
||||||
validator.currentPath.emplace_back();
|
validator.currentPath.emplace_back();
|
||||||
validator.currentPath.back().String() = nodeName;
|
validator.currentPath.back().String() = nodeName;
|
||||||
auto onExit = vstd::makeScopeGuard([&]()
|
auto onExit = vstd::makeScopeGuard([&validator]()
|
||||||
{
|
{
|
||||||
validator.currentPath.pop_back();
|
validator.currentPath.pop_back();
|
||||||
});
|
});
|
||||||
@ -531,6 +531,9 @@ namespace
|
|||||||
ret["title"] = Common::emptyCheck;
|
ret["title"] = Common::emptyCheck;
|
||||||
ret["$schema"] = Common::emptyCheck;
|
ret["$schema"] = Common::emptyCheck;
|
||||||
ret["default"] = Common::emptyCheck;
|
ret["default"] = Common::emptyCheck;
|
||||||
|
ret["defaultIOS"] = Common::emptyCheck;
|
||||||
|
ret["defaultAndroid"] = Common::emptyCheck;
|
||||||
|
ret["defaultWindows"] = Common::emptyCheck;
|
||||||
ret["description"] = Common::emptyCheck;
|
ret["description"] = Common::emptyCheck;
|
||||||
ret["definitions"] = Common::emptyCheck;
|
ret["definitions"] = Common::emptyCheck;
|
||||||
|
|
||||||
@ -643,7 +646,7 @@ namespace Validation
|
|||||||
std::string check(const std::string & schemaName, const JsonNode & data, ValidationData & validator)
|
std::string check(const std::string & schemaName, const JsonNode & data, ValidationData & validator)
|
||||||
{
|
{
|
||||||
validator.usedSchemas.push_back(schemaName);
|
validator.usedSchemas.push_back(schemaName);
|
||||||
auto onscopeExit = vstd::makeScopeGuard([&]()
|
auto onscopeExit = vstd::makeScopeGuard([&validator]()
|
||||||
{
|
{
|
||||||
validator.usedSchemas.pop_back();
|
validator.usedSchemas.pop_back();
|
||||||
});
|
});
|
||||||
@ -659,8 +662,6 @@ namespace Validation
|
|||||||
auto checker = knownFields.find(entry.first);
|
auto checker = knownFields.find(entry.first);
|
||||||
if (checker != knownFields.end())
|
if (checker != knownFields.end())
|
||||||
errors += checker->second(validator, schema, entry.second, data);
|
errors += checker->second(validator, schema, entry.second, data);
|
||||||
//else
|
|
||||||
// errors += validator.makeErrorMessage("Unknown entry in schema " + entry.first);
|
|
||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
@ -687,7 +688,7 @@ namespace Validation
|
|||||||
|
|
||||||
const TFormatMap & getKnownFormats()
|
const TFormatMap & getKnownFormats()
|
||||||
{
|
{
|
||||||
static TFormatMap knownFormats = createFormatMap();
|
static const TFormatMap knownFormats = createFormatMap();
|
||||||
return knownFormats;
|
return knownFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ void JsonWriter::writeEntry(JsonVector::const_iterator entry)
|
|||||||
void JsonWriter::writeString(const std::string & string)
|
void JsonWriter::writeString(const std::string & string)
|
||||||
{
|
{
|
||||||
static const std::string escaped = "\"\\\b\f\n\r\t";
|
static const std::string escaped = "\"\\\b\f\n\r\t";
|
||||||
static const std::array escaped_code = {'\"', '\\', 'b', 'f', 'n', 'r', 't'};
|
static const std::array escapedCode = {'\"', '\\', 'b', 'f', 'n', 'r', 't'};
|
||||||
|
|
||||||
out << '\"';
|
out << '\"';
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@ -68,7 +68,7 @@ void JsonWriter::writeString(const std::string & string)
|
|||||||
for(; pos < string.size(); pos++)
|
for(; pos < string.size(); pos++)
|
||||||
{
|
{
|
||||||
//we need to check if special character was been already escaped
|
//we need to check if special character was been already escaped
|
||||||
if((string[pos] == '\\') && (pos + 1 < string.size()) && (std::find(escaped_code.begin(), escaped_code.end(), string[pos + 1]) != escaped_code.end()))
|
if((string[pos] == '\\') && (pos + 1 < string.size()) && (std::find(escapedCode.begin(), escapedCode.end(), string[pos + 1]) != escapedCode.end()))
|
||||||
{
|
{
|
||||||
pos++; //write unchanged, next simbol also checked
|
pos++; //write unchanged, next simbol also checked
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ void JsonWriter::writeString(const std::string & string)
|
|||||||
if(escapedPos != std::string::npos)
|
if(escapedPos != std::string::npos)
|
||||||
{
|
{
|
||||||
out.write(string.data() + start, pos - start);
|
out.write(string.data() + start, pos - start);
|
||||||
out << '\\' << escaped_code[escapedPos];
|
out << '\\' << escapedCode[escapedPos];
|
||||||
start = pos + 1;
|
start = pos + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
|
|||||||
JsonVector & data = node["allowedTerrains"].Vector();
|
JsonVector & data = node["allowedTerrains"].Vector();
|
||||||
|
|
||||||
for(auto type : allowedTerrains)
|
for(auto type : allowedTerrains)
|
||||||
data.push_back(JsonNode(VLC->terrainTypeHandler->getById(type)->getJsonKey()));
|
data.emplace_back(VLC->terrainTypeHandler->getById(type)->getJsonKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,10 @@ void CModHandler::loadOneMod(std::string modName, const std::string & parent, co
|
|||||||
|
|
||||||
if(CResourceHandler::get("initial")->existsResource(CModInfo::getModFile(modFullName)))
|
if(CResourceHandler::get("initial")->existsResource(CModInfo::getModFile(modFullName)))
|
||||||
{
|
{
|
||||||
CModInfo mod(modFullName, modSettings[modName], JsonNode(CModInfo::getModFile(modFullName)));
|
JsonParsingSettings settings;
|
||||||
|
settings.mode = JsonParsingSettings::JsonFormatMode::JSON; // TODO: remove once Android launcher with its strict parser is gone
|
||||||
|
|
||||||
|
CModInfo mod(modFullName, modSettings[modName], JsonNode(CModInfo::getModFile(modFullName), settings));
|
||||||
if (!parent.empty()) // this is submod, add parent to dependencies
|
if (!parent.empty()) // this is submod, add parent to dependencies
|
||||||
mod.dependencies.insert(parent);
|
mod.dependencies.insert(parent);
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ TEST_F(LuaSpellEffectAPITest, DISABLED_ApplicableOnLeftSideOfField)
|
|||||||
BattleHex hex(2,2);
|
BattleHex hex(2,2);
|
||||||
|
|
||||||
JsonNode first;
|
JsonNode first;
|
||||||
first.Vector().push_back(JsonNode(hex.hex));
|
first.Vector().emplace_back(hex.hex);
|
||||||
first.Vector().push_back(JsonNode());
|
first.Vector().emplace_back();
|
||||||
|
|
||||||
JsonNode targets;
|
JsonNode targets;
|
||||||
targets.Vector().push_back(first);
|
targets.Vector().push_back(first);
|
||||||
|
@ -154,12 +154,12 @@ TEST_F(LuaSpellEffectTest, ApplicableTargetRedirected)
|
|||||||
|
|
||||||
|
|
||||||
JsonNode first;
|
JsonNode first;
|
||||||
first.Vector().push_back(JsonNode(hex1.hex));
|
first.Vector().emplace_back(hex1.hex);
|
||||||
first.Vector().push_back(JsonNode(id1));
|
first.Vector().emplace_back(id1);
|
||||||
|
|
||||||
JsonNode second;
|
JsonNode second;
|
||||||
second.Vector().push_back(JsonNode(hex2.hex));
|
second.Vector().emplace_back(hex2.hex);
|
||||||
second.Vector().push_back(JsonNode(-1));
|
second.Vector().emplace_back(-1);
|
||||||
|
|
||||||
JsonNode targets;
|
JsonNode targets;
|
||||||
targets.Vector().push_back(first);
|
targets.Vector().push_back(first);
|
||||||
@ -193,8 +193,8 @@ TEST_F(LuaSpellEffectTest, ApplyRedirected)
|
|||||||
subject->apply(&serverMock, &mechanicsMock, target);
|
subject->apply(&serverMock, &mechanicsMock, target);
|
||||||
|
|
||||||
JsonNode first;
|
JsonNode first;
|
||||||
first.Vector().push_back(JsonNode(hex1.hex));
|
first.Vector().emplace_back(hex1.hex);
|
||||||
first.Vector().push_back(JsonNode(id1));
|
first.Vector().emplace_back(id1);
|
||||||
|
|
||||||
JsonNode targets;
|
JsonNode targets;
|
||||||
targets.Vector().push_back(first);
|
targets.Vector().push_back(first);
|
||||||
|
Loading…
Reference in New Issue
Block a user