mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Change JsonType to enum class (#393)
Change enum JsonType to enum class JsonType
This commit is contained in:
parent
6df536bb31
commit
26a222ac62
@ -2851,7 +2851,7 @@ void VCAI::requestSent(const CPackForServer *pack, int requestID)
|
||||
|
||||
std::string VCAI::getBattleAIName() const
|
||||
{
|
||||
if(settings["server"]["enemyAI"].getType() == JsonNode::DATA_STRING)
|
||||
if(settings["server"]["enemyAI"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
return settings["server"]["enemyAI"].String();
|
||||
else
|
||||
return "BattleAI";
|
||||
|
@ -45,7 +45,7 @@ bool CCallback::moveHero(const CGHeroInstance *h, int3 dst, bool transit)
|
||||
|
||||
int CCallback::selectionMade(int selection, QueryID queryID)
|
||||
{
|
||||
JsonNode reply(JsonNode::DATA_INTEGER);
|
||||
JsonNode reply(JsonNode::JsonType::DATA_INTEGER);
|
||||
reply.Integer() = selection;
|
||||
return sendQueryReply(reply, queryID);
|
||||
}
|
||||
|
@ -692,11 +692,11 @@ void processCommand(const std::string &message)
|
||||
|
||||
auto extractVector = [=](const std::vector<std::string> & source, const std::string & name)
|
||||
{
|
||||
JsonNode data(JsonNode::DATA_VECTOR);
|
||||
JsonNode data(JsonNode::JsonType::DATA_VECTOR);
|
||||
size_t index = 0;
|
||||
for(auto & line : source)
|
||||
{
|
||||
JsonNode lineNode(JsonNode::DATA_STRUCT);
|
||||
JsonNode lineNode(JsonNode::JsonType::DATA_STRUCT);
|
||||
lineNode["text"].String() = line;
|
||||
lineNode["index"].Integer() = index++;
|
||||
data.Vector().push_back(lineNode);
|
||||
|
@ -1207,14 +1207,14 @@ void CPlayerInterface::showMapObjectSelectDialog(QueryID askID, const Component
|
||||
|
||||
auto selectCallback = [=](int selection)
|
||||
{
|
||||
JsonNode reply(JsonNode::DATA_INTEGER);
|
||||
JsonNode reply(JsonNode::JsonType::DATA_INTEGER);
|
||||
reply.Integer() = selection;
|
||||
cb->sendQueryReply(reply, askID);
|
||||
};
|
||||
|
||||
auto cancelCallback = [=]()
|
||||
{
|
||||
JsonNode reply(JsonNode::DATA_NULL);
|
||||
JsonNode reply(JsonNode::JsonType::DATA_NULL);
|
||||
cb->sendQueryReply(reply, askID);
|
||||
};
|
||||
|
||||
|
@ -1356,7 +1356,7 @@ bool CAnimation::loadFrame(size_t frame, size_t group)
|
||||
}
|
||||
|
||||
//try to get image from def
|
||||
if(source[group][frame].getType() == JsonNode::DATA_NULL)
|
||||
if(source[group][frame].getType() == JsonNode::JsonType::DATA_NULL)
|
||||
{
|
||||
if(defFile)
|
||||
{
|
||||
@ -1411,7 +1411,7 @@ void CAnimation::initFromJson(const JsonNode & config)
|
||||
std::string basepath;
|
||||
basepath = config["basepath"].String();
|
||||
|
||||
JsonNode base(JsonNode::DATA_STRUCT);
|
||||
JsonNode base(JsonNode::JsonType::DATA_STRUCT);
|
||||
base["margins"] = config["margins"];
|
||||
base["width"] = config["width"];
|
||||
base["height"] = config["height"];
|
||||
@ -1423,7 +1423,7 @@ void CAnimation::initFromJson(const JsonNode & config)
|
||||
|
||||
for(const JsonNode & frame : group["frames"].Vector())
|
||||
{
|
||||
JsonNode toAdd(JsonNode::DATA_STRUCT);
|
||||
JsonNode toAdd(JsonNode::JsonType::DATA_STRUCT);
|
||||
JsonUtils::inherit(toAdd, base);
|
||||
toAdd["file"].String() = basepath + frame.String();
|
||||
source[groupID].push_back(toAdd);
|
||||
@ -1438,7 +1438,7 @@ void CAnimation::initFromJson(const JsonNode & config)
|
||||
if (source[group].size() <= frame)
|
||||
source[group].resize(frame+1);
|
||||
|
||||
JsonNode toAdd(JsonNode::DATA_STRUCT);
|
||||
JsonNode toAdd(JsonNode::JsonType::DATA_STRUCT);
|
||||
JsonUtils::inherit(toAdd, base);
|
||||
toAdd["file"].String() = basepath + node["file"].String();
|
||||
source[group][frame] = toAdd;
|
||||
@ -1564,7 +1564,7 @@ void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFra
|
||||
//todo: clone actual loaded Image object
|
||||
JsonNode clone(source[sourceGroup][sourceFrame]);
|
||||
|
||||
if(clone.getType() == JsonNode::DATA_NULL)
|
||||
if(clone.getType() == JsonNode::JsonType::DATA_NULL)
|
||||
{
|
||||
std::string temp = name+":"+boost::lexical_cast<std::string>(sourceGroup)+":"+boost::lexical_cast<std::string>(sourceFrame);
|
||||
clone["file"].String() = temp;
|
||||
|
@ -58,12 +58,12 @@ QVariant toVariant(const JsonNode & node)
|
||||
{
|
||||
switch (node.getType())
|
||||
{
|
||||
break; case JsonNode::DATA_NULL: return QVariant();
|
||||
break; case JsonNode::DATA_BOOL: return QVariant(node.Bool());
|
||||
break; case JsonNode::DATA_FLOAT: return QVariant(node.Float());
|
||||
break; case JsonNode::DATA_STRING: return QVariant(QString::fromUtf8(node.String().c_str()));
|
||||
break; case JsonNode::DATA_VECTOR: return JsonToList(node.Vector());
|
||||
break; case JsonNode::DATA_STRUCT: return JsonToMap(node.Struct());
|
||||
break; case JsonNode::JsonType::DATA_NULL: return QVariant();
|
||||
break; case JsonNode::JsonType::DATA_BOOL: return QVariant(node.Bool());
|
||||
break; case JsonNode::JsonType::DATA_FLOAT: return QVariant(node.Float());
|
||||
break; case JsonNode::JsonType::DATA_STRING: return QVariant(QString::fromUtf8(node.String().c_str()));
|
||||
break; case JsonNode::JsonType::DATA_VECTOR: return JsonToList(node.Vector());
|
||||
break; case JsonNode::JsonType::DATA_STRUCT: return JsonToMap(node.Struct());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ CArtifact * CArtHandler::loadFromJson(const JsonNode & node, const std::string &
|
||||
}
|
||||
|
||||
const JsonNode & warMachine = node["warMachine"];
|
||||
if(warMachine.getType() == JsonNode::DATA_STRING && warMachine.String() != "")
|
||||
if(warMachine.getType() == JsonNode::JsonType::DATA_STRING && warMachine.String() != "")
|
||||
{
|
||||
VLC->modh->identifiers.requestIdentifier("creature", warMachine, [=](si32 id)
|
||||
{
|
||||
@ -396,7 +396,7 @@ void CArtHandler::loadSlots(CArtifact * art, const JsonNode & node)
|
||||
{
|
||||
if (!node["slot"].isNull()) //we assume non-hero slots are irrelevant?
|
||||
{
|
||||
if (node["slot"].getType() == JsonNode::DATA_STRING)
|
||||
if (node["slot"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
addSlot(art, node["slot"].String());
|
||||
else
|
||||
{
|
||||
|
@ -735,7 +735,7 @@ void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & c
|
||||
creature->animDefName = config["graphics"]["animation"].String();
|
||||
|
||||
//FIXME: MOD COMPATIBILITY
|
||||
if (config["abilities"].getType() == JsonNode::DATA_STRUCT)
|
||||
if (config["abilities"].getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
for(auto &ability : config["abilities"].Struct())
|
||||
{
|
||||
@ -752,7 +752,7 @@ void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & c
|
||||
{
|
||||
for(const JsonNode &ability : config["abilities"].Vector())
|
||||
{
|
||||
if (ability.getType() == JsonNode::DATA_VECTOR)
|
||||
if (ability.getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
assert(0); // should be unused now
|
||||
AddAbility(creature, ability.Vector()); // used only for H3 creatures
|
||||
|
@ -501,7 +501,7 @@ void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::strin
|
||||
if(fixedSize)
|
||||
vstd::amax(sz, fixedSize.get());
|
||||
|
||||
a.resize(sz, JsonNode::DATA_STRUCT);
|
||||
a.resize(sz, JsonNode::JsonType::DATA_STRUCT);
|
||||
|
||||
for(const auto & p : stacks)
|
||||
{
|
||||
|
@ -583,11 +583,11 @@ void CModInfo::loadLocalData(const JsonNode & data)
|
||||
bool validated = false;
|
||||
enabled = true;
|
||||
checksum = 0;
|
||||
if (data.getType() == JsonNode::DATA_BOOL)
|
||||
if (data.getType() == JsonNode::JsonType::DATA_BOOL)
|
||||
{
|
||||
enabled = data.Bool();
|
||||
}
|
||||
if (data.getType() == JsonNode::DATA_STRUCT)
|
||||
if (data.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
enabled = data["active"].Bool();
|
||||
validated = data["validated"].Bool();
|
||||
|
@ -128,7 +128,7 @@ std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
|
||||
std::vector<JsonNode> legacyData;
|
||||
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
|
||||
{
|
||||
JsonNode skillNode(JsonNode::DATA_STRUCT);
|
||||
JsonNode skillNode(JsonNode::JsonType::DATA_STRUCT);
|
||||
skillNode["name"].String() = skillNames[id];
|
||||
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
|
||||
{
|
||||
|
@ -354,7 +354,7 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
|
||||
|
||||
ret->mode = CBuilding::BUILD_NORMAL;
|
||||
{
|
||||
if(source["mode"].getType() == JsonNode::DATA_STRING)
|
||||
if(source["mode"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
{
|
||||
auto rawMode = vstd::find_pos(MODES, source["mode"].String());
|
||||
if(rawMode > 0)
|
||||
@ -563,7 +563,7 @@ void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source)
|
||||
|
||||
static void readIcon(JsonNode source, std::string & small, std::string & large)
|
||||
{
|
||||
if (source.getType() == JsonNode::DATA_STRUCT) // don't crash on old format
|
||||
if (source.getType() == JsonNode::JsonType::DATA_STRUCT) // don't crash on old format
|
||||
{
|
||||
small = source["small"].String();
|
||||
large = source["large"].String();
|
||||
|
@ -96,31 +96,31 @@ void JsonWriter::writeNode(const JsonNode &node)
|
||||
{
|
||||
switch(node.getType())
|
||||
{
|
||||
break; case JsonNode::DATA_NULL:
|
||||
break; case JsonNode::JsonType::DATA_NULL:
|
||||
out << "null";
|
||||
|
||||
break; case JsonNode::DATA_BOOL:
|
||||
break; case JsonNode::JsonType::DATA_BOOL:
|
||||
if (node.Bool())
|
||||
out << "true";
|
||||
else
|
||||
out << "false";
|
||||
|
||||
break; case JsonNode::DATA_FLOAT:
|
||||
break; case JsonNode::JsonType::DATA_FLOAT:
|
||||
out << node.Float();
|
||||
|
||||
break; case JsonNode::DATA_STRING:
|
||||
break; case JsonNode::JsonType::DATA_STRING:
|
||||
writeString(node.String());
|
||||
|
||||
break; case JsonNode::DATA_VECTOR:
|
||||
break; case JsonNode::JsonType::DATA_VECTOR:
|
||||
out << "[" << "\n";
|
||||
writeContainer(node.Vector().begin(), node.Vector().end());
|
||||
out << prefix << "]";
|
||||
|
||||
break; case JsonNode::DATA_STRUCT:
|
||||
break; case JsonNode::JsonType::DATA_STRUCT:
|
||||
out << "{" << "\n";
|
||||
writeContainer(node.Struct().begin(), node.Struct().end());
|
||||
out << prefix << "}";
|
||||
break; case JsonNode::DATA_INTEGER:
|
||||
break; case JsonNode::JsonType::DATA_INTEGER:
|
||||
out << node.Integer();
|
||||
}
|
||||
}
|
||||
@ -306,7 +306,7 @@ bool JsonParser::extractString(JsonNode &node)
|
||||
if (!extractString(str))
|
||||
return false;
|
||||
|
||||
node.setType(JsonNode::DATA_STRING);
|
||||
node.setType(JsonNode::JsonType::DATA_STRING);
|
||||
node.String() = str;
|
||||
return true;
|
||||
}
|
||||
@ -354,7 +354,7 @@ bool JsonParser::extractFalse(JsonNode &node)
|
||||
|
||||
bool JsonParser::extractStruct(JsonNode &node)
|
||||
{
|
||||
node.setType(JsonNode::DATA_STRUCT);
|
||||
node.setType(JsonNode::JsonType::DATA_STRUCT);
|
||||
pos++;
|
||||
|
||||
if (!extractWhitespace())
|
||||
@ -396,7 +396,7 @@ bool JsonParser::extractStruct(JsonNode &node)
|
||||
bool JsonParser::extractArray(JsonNode &node)
|
||||
{
|
||||
pos++;
|
||||
node.setType(JsonNode::DATA_VECTOR);
|
||||
node.setType(JsonNode::JsonType::DATA_VECTOR);
|
||||
|
||||
if (!extractWhitespace())
|
||||
return false;
|
||||
@ -536,7 +536,7 @@ bool JsonParser::extractFloat(JsonNode &node)
|
||||
if(negative)
|
||||
result = -result;
|
||||
|
||||
node.setType(JsonNode::DATA_FLOAT);
|
||||
node.setType(JsonNode::JsonType::DATA_FLOAT);
|
||||
node.Float() = result;
|
||||
}
|
||||
else
|
||||
@ -544,7 +544,7 @@ bool JsonParser::extractFloat(JsonNode &node)
|
||||
if(negative)
|
||||
integerPart = -integerPart;
|
||||
|
||||
node.setType(JsonNode::DATA_INTEGER);
|
||||
node.setType(JsonNode::JsonType::DATA_INTEGER);
|
||||
node.Integer() = integerPart;
|
||||
}
|
||||
|
||||
@ -569,12 +569,12 @@ bool JsonParser::error(const std::string &message, bool warning)
|
||||
|
||||
static const std::unordered_map<std::string, JsonNode::JsonType> stringToType =
|
||||
{
|
||||
{"null", JsonNode::DATA_NULL},
|
||||
{"boolean", JsonNode::DATA_BOOL},
|
||||
{"number", JsonNode::DATA_FLOAT},
|
||||
{"string", JsonNode::DATA_STRING},
|
||||
{"array", JsonNode::DATA_VECTOR},
|
||||
{"object", JsonNode::DATA_STRUCT}
|
||||
{"null", JsonNode::JsonType::DATA_NULL},
|
||||
{"boolean", JsonNode::JsonType::DATA_BOOL},
|
||||
{"number", JsonNode::JsonType::DATA_FLOAT},
|
||||
{"string", JsonNode::JsonType::DATA_STRING},
|
||||
{"array", JsonNode::JsonType::DATA_VECTOR},
|
||||
{"object", JsonNode::JsonType::DATA_STRUCT}
|
||||
};
|
||||
|
||||
namespace
|
||||
@ -670,10 +670,10 @@ namespace
|
||||
JsonNode::JsonType type = it->second;
|
||||
|
||||
//FIXME: hack for integer values
|
||||
if(data.isNumber() && type == JsonNode::DATA_FLOAT)
|
||||
if(data.isNumber() && type == JsonNode::JsonType::DATA_FLOAT)
|
||||
return "";
|
||||
|
||||
if(type != data.getType() && data.getType() != JsonNode::DATA_NULL)
|
||||
if(type != data.getType() && data.getType() != JsonNode::JsonType::DATA_NULL)
|
||||
return validator.makeErrorMessage("Type mismatch! Expected " + schema.String());
|
||||
return "";
|
||||
}
|
||||
@ -785,7 +785,7 @@ namespace
|
||||
std::string errors;
|
||||
for (size_t i=0; i<data.Vector().size(); i++)
|
||||
{
|
||||
if (schema.getType() == JsonNode::DATA_VECTOR)
|
||||
if (schema.getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
if (schema.Vector().size() > i)
|
||||
errors += itemEntryCheck(validator, data.Vector(), schema.Vector()[i], i);
|
||||
@ -803,12 +803,12 @@ namespace
|
||||
std::string errors;
|
||||
// "items" is struct or empty (defaults to empty struct) - validation always successful
|
||||
const JsonNode & items = baseSchema["items"];
|
||||
if (items.getType() != JsonNode::DATA_VECTOR)
|
||||
if (items.getType() != JsonNode::JsonType::DATA_VECTOR)
|
||||
return "";
|
||||
|
||||
for (size_t i=items.Vector().size(); i<data.Vector().size(); i++)
|
||||
{
|
||||
if (schema.getType() == JsonNode::DATA_STRUCT)
|
||||
if (schema.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
errors += itemEntryCheck(validator, data.Vector(), schema, i);
|
||||
else if (!schema.isNull() && schema.Bool() == false)
|
||||
errors += validator.makeErrorMessage("Unknown entry found");
|
||||
@ -896,7 +896,7 @@ namespace
|
||||
{
|
||||
if (!data[deps.first].isNull())
|
||||
{
|
||||
if (deps.second.getType() == JsonNode::DATA_VECTOR)
|
||||
if (deps.second.getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
JsonVector depList = deps.second.Vector();
|
||||
for(auto & depEntry : depList)
|
||||
@ -947,7 +947,7 @@ namespace
|
||||
if (baseSchema["properties"].Struct().count(entry.first) == 0)
|
||||
{
|
||||
// try generic additionalItems schema
|
||||
if (schema.getType() == JsonNode::DATA_STRUCT)
|
||||
if (schema.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
errors += propertyEntryCheck(validator, entry.second, schema, entry.first);
|
||||
|
||||
// or, additionalItems field can be bool which indicates if such items are allowed
|
||||
@ -1134,7 +1134,7 @@ namespace Validation
|
||||
for(const JsonNode &path : currentPath)
|
||||
{
|
||||
errors += "/";
|
||||
if (path.getType() == JsonNode::DATA_STRING)
|
||||
if (path.getType() == JsonNode::JsonType::DATA_STRING)
|
||||
errors += path.String();
|
||||
else
|
||||
errors += boost::lexical_cast<std::string>(static_cast<unsigned>(path.Float()));
|
||||
@ -1187,12 +1187,12 @@ namespace Validation
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case JsonNode::DATA_FLOAT:
|
||||
case JsonNode::DATA_INTEGER:
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
case JsonNode::JsonType::DATA_INTEGER:
|
||||
return numberFields;
|
||||
case JsonNode::DATA_STRING: return stringFields;
|
||||
case JsonNode::DATA_VECTOR: return vectorFields;
|
||||
case JsonNode::DATA_STRUCT: return structFields;
|
||||
case JsonNode::JsonType::DATA_STRING: return stringFields;
|
||||
case JsonNode::JsonType::DATA_VECTOR: return vectorFields;
|
||||
case JsonNode::JsonType::DATA_STRUCT: return structFields;
|
||||
default: return commonFields;
|
||||
}
|
||||
}
|
||||
|
158
lib/JsonNode.cpp
158
lib/JsonNode.cpp
@ -28,20 +28,20 @@ class CModHandler;
|
||||
static const JsonNode nullNode;
|
||||
|
||||
JsonNode::JsonNode(JsonType Type):
|
||||
type(DATA_NULL)
|
||||
type(JsonType::DATA_NULL)
|
||||
{
|
||||
setType(Type);
|
||||
}
|
||||
|
||||
JsonNode::JsonNode(const char *data, size_t datasize):
|
||||
type(DATA_NULL)
|
||||
type(JsonType::DATA_NULL)
|
||||
{
|
||||
JsonParser parser(data, datasize);
|
||||
*this = parser.parse("<unknown>");
|
||||
}
|
||||
|
||||
JsonNode::JsonNode(ResourceID && fileURI):
|
||||
type(DATA_NULL)
|
||||
type(JsonType::DATA_NULL)
|
||||
{
|
||||
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||
|
||||
@ -50,7 +50,7 @@ JsonNode::JsonNode(ResourceID && fileURI):
|
||||
}
|
||||
|
||||
JsonNode::JsonNode(const ResourceID & fileURI):
|
||||
type(DATA_NULL)
|
||||
type(JsonType::DATA_NULL)
|
||||
{
|
||||
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||
|
||||
@ -59,7 +59,7 @@ JsonNode::JsonNode(const ResourceID & fileURI):
|
||||
}
|
||||
|
||||
JsonNode::JsonNode(ResourceID && fileURI, bool &isValidSyntax):
|
||||
type(DATA_NULL)
|
||||
type(JsonType::DATA_NULL)
|
||||
{
|
||||
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||
|
||||
@ -69,25 +69,25 @@ JsonNode::JsonNode(ResourceID && fileURI, bool &isValidSyntax):
|
||||
}
|
||||
|
||||
JsonNode::JsonNode(const JsonNode ©):
|
||||
type(DATA_NULL),
|
||||
type(JsonType::DATA_NULL),
|
||||
meta(copy.meta)
|
||||
{
|
||||
setType(copy.getType());
|
||||
switch(type)
|
||||
{
|
||||
break; case DATA_NULL:
|
||||
break; case DATA_BOOL: Bool() = copy.Bool();
|
||||
break; case DATA_FLOAT: Float() = copy.Float();
|
||||
break; case DATA_STRING: String() = copy.String();
|
||||
break; case DATA_VECTOR: Vector() = copy.Vector();
|
||||
break; case DATA_STRUCT: Struct() = copy.Struct();
|
||||
break; case DATA_INTEGER:Integer() = copy.Integer();
|
||||
break; case JsonType::DATA_NULL:
|
||||
break; case JsonType::DATA_BOOL: Bool() = copy.Bool();
|
||||
break; case JsonType::DATA_FLOAT: Float() = copy.Float();
|
||||
break; case JsonType::DATA_STRING: String() = copy.String();
|
||||
break; case JsonType::DATA_VECTOR: Vector() = copy.Vector();
|
||||
break; case JsonType::DATA_STRUCT: Struct() = copy.Struct();
|
||||
break; case JsonType::DATA_INTEGER:Integer() = copy.Integer();
|
||||
}
|
||||
}
|
||||
|
||||
JsonNode::~JsonNode()
|
||||
{
|
||||
setType(DATA_NULL);
|
||||
setType(JsonType::DATA_NULL);
|
||||
}
|
||||
|
||||
void JsonNode::swap(JsonNode &b)
|
||||
@ -110,13 +110,13 @@ bool JsonNode::operator == (const JsonNode &other) const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case DATA_NULL: return true;
|
||||
case DATA_BOOL: return Bool() == other.Bool();
|
||||
case DATA_FLOAT: return Float() == other.Float();
|
||||
case DATA_STRING: return String() == other.String();
|
||||
case DATA_VECTOR: return Vector() == other.Vector();
|
||||
case DATA_STRUCT: return Struct() == other.Struct();
|
||||
case DATA_INTEGER:return Integer()== other.Integer();
|
||||
case JsonType::DATA_NULL: return true;
|
||||
case JsonType::DATA_BOOL: return Bool() == other.Bool();
|
||||
case JsonType::DATA_FLOAT: return Float() == other.Float();
|
||||
case JsonType::DATA_STRING: return String() == other.String();
|
||||
case JsonType::DATA_VECTOR: return Vector() == other.Vector();
|
||||
case JsonType::DATA_STRUCT: return Struct() == other.Struct();
|
||||
case JsonType::DATA_INTEGER:return Integer()== other.Integer();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -139,14 +139,14 @@ void JsonNode::setMeta(std::string metadata, bool recursive)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
break; case DATA_VECTOR:
|
||||
break; case JsonType::DATA_VECTOR:
|
||||
{
|
||||
for(auto & node : Vector())
|
||||
{
|
||||
node.setMeta(metadata);
|
||||
}
|
||||
}
|
||||
break; case DATA_STRUCT:
|
||||
break; case JsonType::DATA_STRUCT:
|
||||
{
|
||||
for(auto & node : Struct())
|
||||
{
|
||||
@ -163,14 +163,14 @@ void JsonNode::setType(JsonType Type)
|
||||
return;
|
||||
|
||||
//float<->int conversion
|
||||
if(type == DATA_FLOAT && Type == DATA_INTEGER)
|
||||
if(type == JsonType::DATA_FLOAT && Type == JsonType::DATA_INTEGER)
|
||||
{
|
||||
si64 converted = data.Float;
|
||||
type = Type;
|
||||
data.Integer = converted;
|
||||
return;
|
||||
}
|
||||
else if(type == DATA_INTEGER && Type == DATA_FLOAT)
|
||||
else if(type == JsonType::DATA_INTEGER && Type == JsonType::DATA_FLOAT)
|
||||
{
|
||||
double converted = data.Integer;
|
||||
type = Type;
|
||||
@ -179,14 +179,14 @@ void JsonNode::setType(JsonType Type)
|
||||
}
|
||||
|
||||
//Reset node to nullptr
|
||||
if (Type != DATA_NULL)
|
||||
setType(DATA_NULL);
|
||||
if (Type != JsonType::DATA_NULL)
|
||||
setType(JsonType::DATA_NULL);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
break; case DATA_STRING: delete data.String;
|
||||
break; case DATA_VECTOR: delete data.Vector;
|
||||
break; case DATA_STRUCT: delete data.Struct;
|
||||
break; case JsonType::DATA_STRING: delete data.String;
|
||||
break; case JsonType::DATA_VECTOR: delete data.Vector;
|
||||
break; case JsonType::DATA_STRUCT: delete data.Struct;
|
||||
break; default:
|
||||
break;
|
||||
}
|
||||
@ -194,124 +194,124 @@ void JsonNode::setType(JsonType Type)
|
||||
type = Type;
|
||||
switch(type)
|
||||
{
|
||||
break; case DATA_NULL:
|
||||
break; case DATA_BOOL: data.Bool = false;
|
||||
break; case DATA_FLOAT: data.Float = 0;
|
||||
break; case DATA_STRING: data.String = new std::string();
|
||||
break; case DATA_VECTOR: data.Vector = new JsonVector();
|
||||
break; case DATA_STRUCT: data.Struct = new JsonMap();
|
||||
break; case DATA_INTEGER: data.Integer = 0;
|
||||
break; case JsonType::DATA_NULL:
|
||||
break; case JsonType::DATA_BOOL: data.Bool = false;
|
||||
break; case JsonType::DATA_FLOAT: data.Float = 0;
|
||||
break; case JsonType::DATA_STRING: data.String = new std::string();
|
||||
break; case JsonType::DATA_VECTOR: data.Vector = new JsonVector();
|
||||
break; case JsonType::DATA_STRUCT: data.Struct = new JsonMap();
|
||||
break; case JsonType::DATA_INTEGER: data.Integer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool JsonNode::isNull() const
|
||||
{
|
||||
return type == DATA_NULL;
|
||||
return type == JsonType::DATA_NULL;
|
||||
}
|
||||
|
||||
bool JsonNode::isNumber() const
|
||||
{
|
||||
return type == DATA_INTEGER || type == DATA_FLOAT;
|
||||
return type == JsonType::DATA_INTEGER || type == JsonType::DATA_FLOAT;
|
||||
}
|
||||
|
||||
void JsonNode::clear()
|
||||
{
|
||||
setType(DATA_NULL);
|
||||
setType(JsonType::DATA_NULL);
|
||||
}
|
||||
|
||||
bool & JsonNode::Bool()
|
||||
{
|
||||
setType(DATA_BOOL);
|
||||
setType(JsonType::DATA_BOOL);
|
||||
return data.Bool;
|
||||
}
|
||||
|
||||
double & JsonNode::Float()
|
||||
{
|
||||
setType(DATA_FLOAT);
|
||||
setType(JsonType::DATA_FLOAT);
|
||||
return data.Float;
|
||||
}
|
||||
|
||||
si64 & JsonNode::Integer()
|
||||
{
|
||||
setType(DATA_INTEGER);
|
||||
setType(JsonType::DATA_INTEGER);
|
||||
return data.Integer;
|
||||
}
|
||||
|
||||
std::string & JsonNode::String()
|
||||
{
|
||||
setType(DATA_STRING);
|
||||
setType(JsonType::DATA_STRING);
|
||||
return *data.String;
|
||||
}
|
||||
|
||||
JsonVector & JsonNode::Vector()
|
||||
{
|
||||
setType(DATA_VECTOR);
|
||||
setType(JsonType::DATA_VECTOR);
|
||||
return *data.Vector;
|
||||
}
|
||||
|
||||
JsonMap & JsonNode::Struct()
|
||||
{
|
||||
setType(DATA_STRUCT);
|
||||
setType(JsonType::DATA_STRUCT);
|
||||
return *data.Struct;
|
||||
}
|
||||
|
||||
const bool boolDefault = false;
|
||||
bool JsonNode::Bool() const
|
||||
{
|
||||
if (type == DATA_NULL)
|
||||
if (type == JsonType::DATA_NULL)
|
||||
return boolDefault;
|
||||
assert(type == DATA_BOOL);
|
||||
assert(type == JsonType::DATA_BOOL);
|
||||
return data.Bool;
|
||||
}
|
||||
|
||||
const double floatDefault = 0;
|
||||
double JsonNode::Float() const
|
||||
{
|
||||
if(type == DATA_NULL)
|
||||
if(type == JsonType::DATA_NULL)
|
||||
return floatDefault;
|
||||
else if(type == DATA_INTEGER)
|
||||
else if(type == JsonType::DATA_INTEGER)
|
||||
return data.Integer;
|
||||
|
||||
assert(type == DATA_FLOAT);
|
||||
assert(type == JsonType::DATA_FLOAT);
|
||||
return data.Float;
|
||||
}
|
||||
|
||||
const si64 integetDefault = 0;
|
||||
si64 JsonNode::Integer() const
|
||||
{
|
||||
if(type == DATA_NULL)
|
||||
if(type == JsonType::DATA_NULL)
|
||||
return integetDefault;
|
||||
else if(type == DATA_FLOAT)
|
||||
else if(type == JsonType::DATA_FLOAT)
|
||||
return data.Float;
|
||||
|
||||
assert(type == DATA_INTEGER);
|
||||
assert(type == JsonType::DATA_INTEGER);
|
||||
return data.Integer;
|
||||
}
|
||||
|
||||
const std::string stringDefault = std::string();
|
||||
const std::string & JsonNode::String() const
|
||||
{
|
||||
if (type == DATA_NULL)
|
||||
if (type == JsonType::DATA_NULL)
|
||||
return stringDefault;
|
||||
assert(type == DATA_STRING);
|
||||
assert(type == JsonType::DATA_STRING);
|
||||
return *data.String;
|
||||
}
|
||||
|
||||
const JsonVector vectorDefault = JsonVector();
|
||||
const JsonVector & JsonNode::Vector() const
|
||||
{
|
||||
if (type == DATA_NULL)
|
||||
if (type == JsonType::DATA_NULL)
|
||||
return vectorDefault;
|
||||
assert(type == DATA_VECTOR);
|
||||
assert(type == JsonType::DATA_VECTOR);
|
||||
return *data.Vector;
|
||||
}
|
||||
|
||||
const JsonMap mapDefault = JsonMap();
|
||||
const JsonMap & JsonNode::Struct() const
|
||||
{
|
||||
if (type == DATA_NULL)
|
||||
if (type == JsonType::DATA_NULL)
|
||||
return mapDefault;
|
||||
assert(type == DATA_STRUCT);
|
||||
assert(type == JsonType::DATA_STRUCT);
|
||||
return *data.Struct;
|
||||
}
|
||||
|
||||
@ -341,7 +341,7 @@ Node & resolvePointer(Node & in, const std::string & pointer)
|
||||
std::string entry = pointer.substr(1, splitPos -1);
|
||||
std::string remainer = splitPos == std::string::npos ? "" : pointer.substr(splitPos);
|
||||
|
||||
if (in.getType() == JsonNode::DATA_VECTOR)
|
||||
if (in.getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
if (entry.find_first_not_of("0123456789") != std::string::npos) // non-numbers in string
|
||||
throw std::runtime_error("Invalid Json pointer");
|
||||
@ -432,13 +432,13 @@ void JsonUtils::resolveIdentifier(si32 &var, const JsonNode &node, std::string n
|
||||
{
|
||||
switch (value.getType())
|
||||
{
|
||||
case JsonNode::DATA_INTEGER:
|
||||
case JsonNode::JsonType::DATA_INTEGER:
|
||||
var = value.Integer();
|
||||
break;
|
||||
case JsonNode::DATA_FLOAT:
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
var = value.Float();
|
||||
break;
|
||||
case JsonNode::DATA_STRING:
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
VLC->modh->identifiers.requestIdentifier(value, [&](si32 identifier)
|
||||
{
|
||||
var = identifier;
|
||||
@ -454,13 +454,13 @@ void JsonUtils::resolveIdentifier(const JsonNode &node, si32 &var)
|
||||
{
|
||||
switch (node.getType())
|
||||
{
|
||||
case JsonNode::DATA_INTEGER:
|
||||
case JsonNode::JsonType::DATA_INTEGER:
|
||||
var = node.Integer();
|
||||
break;
|
||||
case JsonNode::DATA_FLOAT:
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
var = node.Float();
|
||||
break;
|
||||
case JsonNode::DATA_STRING:
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
VLC->modh->identifiers.requestIdentifier(node, [&](si32 identifier)
|
||||
{
|
||||
var = identifier;
|
||||
@ -519,10 +519,10 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
|
||||
{
|
||||
switch (value->getType())
|
||||
{
|
||||
case JsonNode::DATA_STRING:
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
b->duration = parseByMap(bonusDurationMap, value, "duration type ");
|
||||
break;
|
||||
case JsonNode::DATA_VECTOR:
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
{
|
||||
ui16 dur = 0;
|
||||
for (const JsonNode & d : value->Vector())
|
||||
@ -548,10 +548,10 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
|
||||
{
|
||||
switch (limiter.getType())
|
||||
{
|
||||
case JsonNode::DATA_STRING: //pre-defined limiters
|
||||
case JsonNode::JsonType::DATA_STRING: //pre-defined limiters
|
||||
b->limiter = parseByMap(bonusLimiterMap, &limiter, "limiter type ");
|
||||
break;
|
||||
case JsonNode::DATA_STRUCT: //customizable limiters
|
||||
case JsonNode::JsonType::DATA_STRUCT: //customizable limiters
|
||||
{
|
||||
std::shared_ptr<ILimiter> l;
|
||||
if (limiter["type"].String() == "CREATURE_TYPE_LIMITER")
|
||||
@ -778,7 +778,7 @@ const JsonNode & JsonUtils::getSchema(std::string URI)
|
||||
|
||||
void JsonUtils::merge(JsonNode & dest, JsonNode & source)
|
||||
{
|
||||
if (dest.getType() == JsonNode::DATA_NULL)
|
||||
if (dest.getType() == JsonNode::JsonType::DATA_NULL)
|
||||
{
|
||||
std::swap(dest, source);
|
||||
return;
|
||||
@ -786,21 +786,21 @@ void JsonUtils::merge(JsonNode & dest, JsonNode & source)
|
||||
|
||||
switch (source.getType())
|
||||
{
|
||||
case JsonNode::DATA_NULL:
|
||||
case JsonNode::JsonType::DATA_NULL:
|
||||
{
|
||||
dest.clear();
|
||||
break;
|
||||
}
|
||||
case JsonNode::DATA_BOOL:
|
||||
case JsonNode::DATA_FLOAT:
|
||||
case JsonNode::DATA_INTEGER:
|
||||
case JsonNode::DATA_STRING:
|
||||
case JsonNode::DATA_VECTOR:
|
||||
case JsonNode::JsonType::DATA_BOOL:
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
case JsonNode::JsonType::DATA_INTEGER:
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
{
|
||||
std::swap(dest, source);
|
||||
break;
|
||||
}
|
||||
case JsonNode::DATA_STRUCT:
|
||||
case JsonNode::JsonType::DATA_STRUCT:
|
||||
{
|
||||
//recursively merge all entries from struct
|
||||
for(auto & node : source.Struct())
|
||||
|
@ -19,7 +19,7 @@ class ResourceID;
|
||||
class DLL_LINKAGE JsonNode
|
||||
{
|
||||
public:
|
||||
enum JsonType
|
||||
enum class JsonType
|
||||
{
|
||||
DATA_NULL,
|
||||
DATA_BOOL,
|
||||
@ -49,7 +49,7 @@ public:
|
||||
std::string meta;
|
||||
|
||||
//Create empty node
|
||||
JsonNode(JsonType Type = DATA_NULL);
|
||||
JsonNode(JsonType Type = JsonType::DATA_NULL);
|
||||
//Create tree from Json-formatted input
|
||||
explicit JsonNode(const char * data, size_t datasize);
|
||||
//Create tree from JSON file
|
||||
@ -117,16 +117,16 @@ public:
|
||||
h & meta;
|
||||
h & type;
|
||||
switch (type) {
|
||||
break; case DATA_NULL:
|
||||
break; case DATA_BOOL: h & data.Bool;
|
||||
break; case DATA_FLOAT: h & data.Float;
|
||||
break; case DATA_STRING: h & data.String;
|
||||
break; case DATA_VECTOR: h & data.Vector;
|
||||
break; case DATA_STRUCT: h & data.Struct;
|
||||
break; case JsonType::DATA_NULL:
|
||||
break; case JsonType::DATA_BOOL: h & data.Bool;
|
||||
break; case JsonType::DATA_FLOAT: h & data.Float;
|
||||
break; case JsonType::DATA_STRING: h & data.String;
|
||||
break; case JsonType::DATA_VECTOR: h & data.Vector;
|
||||
break; case JsonType::DATA_STRUCT: h & data.Struct;
|
||||
}
|
||||
if(version >= 770)
|
||||
{
|
||||
if(type == DATA_INTEGER)
|
||||
if(type == JsonType::DATA_INTEGER)
|
||||
h & data.Integer;
|
||||
}
|
||||
}
|
||||
|
@ -1546,7 +1546,7 @@ void CGHeroInstance::serializeCommonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
const JsonNode & portraitNode = handler.getCurrent()["portrait"];
|
||||
|
||||
if(portraitNode.getType() == JsonNode::DATA_STRING)
|
||||
if(portraitNode.getType() == JsonNode::JsonType::DATA_STRING)
|
||||
handler.serializeId("portrait", portrait, -1, &VLC->heroh->decodeHero, &VLC->heroh->encodeHero);
|
||||
else
|
||||
handler.serializeInt("portrait", portrait, -1);
|
||||
@ -1574,7 +1574,7 @@ void CGHeroInstance::serializeCommonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
auto primarySkills = handler.enterStruct("primarySkills");
|
||||
|
||||
if(primarySkills.get().getType() == JsonNode::DATA_STRUCT)
|
||||
if(primarySkills.get().getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
for(int i = 0; i < GameConstants::PRIMARY_SKILLS; ++i)
|
||||
{
|
||||
@ -1625,7 +1625,7 @@ void CGHeroInstance::serializeCommonOptions(JsonSerializeFormat & handler)
|
||||
const JsonNode & skillMap = handler.getCurrent();
|
||||
|
||||
secSkills.clear();
|
||||
if(skillMap.getType() == JsonNode::DATA_NULL)
|
||||
if(skillMap.getType() == JsonNode::JsonType::DATA_NULL)
|
||||
{
|
||||
secSkills.push_back(std::pair<SecondarySkill,ui8>(SecondarySkill::DEFAULT, -1));
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void CObjectClassesHandler::loadObject(std::string scope, std::string name, cons
|
||||
|
||||
void CObjectClassesHandler::loadSubObject(const std::string & identifier, JsonNode config, si32 ID, boost::optional<si32> subID)
|
||||
{
|
||||
config.setType(JsonNode::DATA_STRUCT); // ensure that input is not NULL
|
||||
config.setType(JsonNode::JsonType::DATA_STRUCT); // ensure that input is not NULL
|
||||
assert(objects.count(ID));
|
||||
if (subID)
|
||||
{
|
||||
@ -398,7 +398,7 @@ void AObjectTypeHandler::init(const JsonNode & input, boost::optional<std::strin
|
||||
|
||||
for (auto entry : input["templates"].Struct())
|
||||
{
|
||||
entry.second.setType(JsonNode::DATA_STRUCT);
|
||||
entry.second.setType(JsonNode::JsonType::DATA_STRUCT);
|
||||
JsonUtils::inherit(entry.second, base);
|
||||
|
||||
ObjectTemplate tmpl;
|
||||
@ -449,7 +449,7 @@ void AObjectTypeHandler::addTemplate(const ObjectTemplate & templ)
|
||||
|
||||
void AObjectTypeHandler::addTemplate(JsonNode config)
|
||||
{
|
||||
config.setType(JsonNode::DATA_STRUCT); // ensure that input is not null
|
||||
config.setType(JsonNode::JsonType::DATA_STRUCT); // ensure that input is not null
|
||||
JsonUtils::inherit(config, base);
|
||||
ObjectTemplate tmpl;
|
||||
tmpl.id = Obj(type);
|
||||
|
@ -198,14 +198,14 @@ void CDwellingInstanceConstructor::configureObject(CGObjectInstance * object, CR
|
||||
|
||||
bool guarded = false; //TODO: serialize for sanity
|
||||
|
||||
if (guards.getType() == JsonNode::DATA_BOOL) //simple switch
|
||||
if (guards.getType() == JsonNode::JsonType::DATA_BOOL) //simple switch
|
||||
{
|
||||
if (guards.Bool())
|
||||
{
|
||||
guarded = true;
|
||||
}
|
||||
}
|
||||
else if (guards.getType() == JsonNode::DATA_VECTOR) //custom guards (eg. Elemental Conflux)
|
||||
else if (guards.getType() == JsonNode::JsonType::DATA_VECTOR) //custom guards (eg. Elemental Conflux)
|
||||
{
|
||||
for (auto & stack : JsonRandom::loadCreatures(guards, rng))
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ namespace JsonRandom
|
||||
|
||||
ArtifactID loadArtifact(const JsonNode & value, CRandomGenerator & rng)
|
||||
{
|
||||
if (value.getType() == JsonNode::DATA_STRING)
|
||||
if (value.getType() == JsonNode::JsonType::DATA_STRING)
|
||||
return ArtifactID(VLC->modh->identifiers.getIdentifier("artifact", value).get());
|
||||
|
||||
std::set<CArtifact::EartClass> allowedClasses;
|
||||
@ -77,13 +77,13 @@ namespace JsonRandom
|
||||
ui32 minValue = 0;
|
||||
ui32 maxValue = std::numeric_limits<ui32>::max();
|
||||
|
||||
if (value["class"].getType() == JsonNode::DATA_STRING)
|
||||
if (value["class"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
allowedClasses.insert(VLC->arth->stringToClass(value["class"].String()));
|
||||
else
|
||||
for (auto & entry : value["class"].Vector())
|
||||
allowedClasses.insert(VLC->arth->stringToClass(entry.String()));
|
||||
|
||||
if (value["slot"].getType() == JsonNode::DATA_STRING)
|
||||
if (value["slot"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
allowedPositions.insert(VLC->arth->stringToSlot(value["class"].String()));
|
||||
else
|
||||
for (auto & entry : value["slot"].Vector())
|
||||
@ -127,9 +127,9 @@ namespace JsonRandom
|
||||
|
||||
SpellID loadSpell(const JsonNode & value, CRandomGenerator & rng, std::vector<SpellID> spells)
|
||||
{
|
||||
if (value.getType() == JsonNode::DATA_STRING)
|
||||
if (value.getType() == JsonNode::JsonType::DATA_STRING)
|
||||
return SpellID(VLC->modh->identifiers.getIdentifier("spell", value).get());
|
||||
if (value["type"].getType() == JsonNode::DATA_STRING)
|
||||
if (value["type"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
return SpellID(VLC->modh->identifiers.getIdentifier("spell", value["type"]).get());
|
||||
|
||||
vstd::erase_if(spells, [=](SpellID spell)
|
||||
|
@ -788,7 +788,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; i++)
|
||||
if(tempOwner.getNum() & 1<<i)
|
||||
{
|
||||
JsonNode one(JsonNode::DATA_STRING);
|
||||
JsonNode one(JsonNode::JsonType::DATA_STRING);
|
||||
one.String() = GameConstants::RESOURCE_NAMES[i];
|
||||
node.Vector().push_back(one);
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
|
||||
|
||||
for(auto type : allowedTerrains)
|
||||
{
|
||||
JsonNode value(JsonNode::DATA_STRING);
|
||||
JsonNode value(JsonNode::JsonType::DATA_STRING);
|
||||
value.String() = GameConstants::TERRAIN_NAMES[type.num];
|
||||
data.push_back(value);
|
||||
}
|
||||
@ -379,7 +379,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
|
||||
|
||||
for(size_t i=0; i < height; i++)
|
||||
{
|
||||
JsonNode lineNode(JsonNode::DATA_STRING);
|
||||
JsonNode lineNode(JsonNode::JsonType::DATA_STRING);
|
||||
|
||||
std::string & line = lineNode.String();
|
||||
line.resize(width);
|
||||
|
@ -232,7 +232,7 @@ namespace TriggeredEventsDetail
|
||||
default:
|
||||
{
|
||||
//old format
|
||||
if (data["type"].getType() == JsonNode::DATA_STRING)
|
||||
if (data["type"].getType() == JsonNode::JsonType::DATA_STRING)
|
||||
{
|
||||
auto identifier = VLC->modh->identifiers.getIdentifier(data["type"]);
|
||||
if(identifier)
|
||||
@ -567,10 +567,10 @@ void CMapFormatJson::readTeams(JsonDeserializer & handler)
|
||||
auto teams = handler.enterArray("teams");
|
||||
const JsonNode & src = teams.get();
|
||||
|
||||
if(src.getType() != JsonNode::DATA_VECTOR)
|
||||
if(src.getType() != JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
// No alliances
|
||||
if(src.getType() != JsonNode::DATA_NULL)
|
||||
if(src.getType() != JsonNode::JsonType::DATA_NULL)
|
||||
logGlobal->error("Invalid teams field type");
|
||||
|
||||
mapHeader->howManyTeams = 0;
|
||||
@ -625,14 +625,14 @@ void CMapFormatJson::writeTeams(JsonSerializer & handler)
|
||||
JsonNode & dest = teams.get();
|
||||
|
||||
//construct output
|
||||
dest.setType(JsonNode::DATA_VECTOR);
|
||||
dest.setType(JsonNode::JsonType::DATA_VECTOR);
|
||||
|
||||
for(const std::set<PlayerColor> & teamData : teamsData)
|
||||
{
|
||||
JsonNode team(JsonNode::DATA_VECTOR);
|
||||
JsonNode team(JsonNode::JsonType::DATA_VECTOR);
|
||||
for(const PlayerColor & player : teamData)
|
||||
{
|
||||
JsonNode member(JsonNode::DATA_STRING);
|
||||
JsonNode member(JsonNode::JsonType::DATA_STRING);
|
||||
member.String() = GameConstants::PLAYER_COLOR_NAMES[player.getNum()];
|
||||
team.Vector().push_back(std::move(member));
|
||||
}
|
||||
@ -747,7 +747,7 @@ void CMapFormatJson::writeDisposedHeroes(JsonSerializeFormat & handler)
|
||||
for(int playerNum = 0; playerNum < PlayerColor::PLAYER_LIMIT_I; playerNum++)
|
||||
if((1 << playerNum) & hero.players)
|
||||
{
|
||||
JsonNode player(JsonNode::DATA_STRING);
|
||||
JsonNode player(JsonNode::JsonType::DATA_STRING);
|
||||
player.String() = GameConstants::PLAYER_COLOR_NAMES[playerNum];
|
||||
players.push_back(player);
|
||||
}
|
||||
@ -1347,7 +1347,7 @@ void CMapSaverJson::writeTerrain()
|
||||
void CMapSaverJson::writeObjects()
|
||||
{
|
||||
logGlobal->trace("Saving objects");
|
||||
JsonNode data(JsonNode::DATA_STRUCT);
|
||||
JsonNode data(JsonNode::JsonType::DATA_STRUCT);
|
||||
|
||||
JsonSerializer handler(mapObjectResolver.get(), data);
|
||||
|
||||
@ -1361,7 +1361,7 @@ void CMapSaverJson::writeObjects()
|
||||
|
||||
if(map->grailPos.valid())
|
||||
{
|
||||
JsonNode grail(JsonNode::DATA_STRUCT);
|
||||
JsonNode grail(JsonNode::JsonType::DATA_STRUCT);
|
||||
grail["type"].String() = "grail";
|
||||
|
||||
grail["x"].Float() = map->grailPos.x;
|
||||
|
@ -137,7 +137,7 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const
|
||||
if (!zoneNode["treasure"].isNull())
|
||||
{
|
||||
//TODO: parse vector of different treasure settings
|
||||
if (zoneNode["treasure"].getType() == JsonNode::DATA_STRUCT)
|
||||
if (zoneNode["treasure"].getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
auto treasureInfo = zoneNode["treasure"].Struct();
|
||||
{
|
||||
@ -148,7 +148,7 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const
|
||||
zone->addTreasureInfo(ti);
|
||||
}
|
||||
}
|
||||
else if (zoneNode["treasure"].getType() == JsonNode::DATA_VECTOR)
|
||||
else if (zoneNode["treasure"].getType() == JsonNode::JsonType::DATA_VECTOR)
|
||||
{
|
||||
for (auto treasureInfo : zoneNode["treasure"].Vector())
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ JsonDeserializer::JsonDeserializer(const IInstanceResolver * instanceResolver_,
|
||||
void JsonDeserializer::serializeInternal(const std::string & fieldName, boost::logic::tribool & value)
|
||||
{
|
||||
const JsonNode & data = current->operator[](fieldName);
|
||||
if(data.getType() != JsonNode::DATA_BOOL)
|
||||
if(data.getType() != JsonNode::JsonType::DATA_BOOL)
|
||||
value = boost::logic::indeterminate;
|
||||
else
|
||||
value = data.Bool();
|
||||
|
@ -79,7 +79,7 @@ JsonStructSerializer::JsonStructSerializer(JsonSerializeFormat & owner_, const s
|
||||
optional(false)
|
||||
{
|
||||
if(owner.saving)
|
||||
thisNode->setType(JsonNode::DATA_STRUCT);
|
||||
thisNode->setType(JsonNode::JsonType::DATA_STRUCT);
|
||||
}
|
||||
|
||||
JsonStructSerializer::JsonStructSerializer(JsonSerializeHelper & parent, const std::string & fieldName):
|
||||
@ -87,7 +87,7 @@ JsonStructSerializer::JsonStructSerializer(JsonSerializeHelper & parent, const s
|
||||
optional(false)
|
||||
{
|
||||
if(owner.saving)
|
||||
thisNode->setType(JsonNode::DATA_STRUCT);
|
||||
thisNode->setType(JsonNode::JsonType::DATA_STRUCT);
|
||||
}
|
||||
|
||||
JsonStructSerializer::JsonStructSerializer(JsonSerializeFormat & owner_, JsonNode * thisNode_):
|
||||
@ -95,7 +95,7 @@ JsonStructSerializer::JsonStructSerializer(JsonSerializeFormat & owner_, JsonNod
|
||||
optional(false)
|
||||
{
|
||||
if(owner.saving)
|
||||
thisNode->setType(JsonNode::DATA_STRUCT);
|
||||
thisNode->setType(JsonNode::JsonType::DATA_STRUCT);
|
||||
}
|
||||
|
||||
JsonStructSerializer::~JsonStructSerializer()
|
||||
@ -141,7 +141,7 @@ void JsonArraySerializer::resize(const size_t newSize, JsonNode::JsonType type)
|
||||
resize(newSize);
|
||||
|
||||
for(JsonNode & n : thisNode->Vector())
|
||||
if(n.getType() == JsonNode::DATA_NULL)
|
||||
if(n.getType() == JsonNode::JsonType::DATA_NULL)
|
||||
n.setType(type);
|
||||
}
|
||||
|
||||
|
@ -75,13 +75,13 @@ public:
|
||||
JsonStructSerializer enterStruct(const size_t index);
|
||||
|
||||
template <typename Container>
|
||||
void syncSize(Container & c, JsonNode::JsonType type = JsonNode::DATA_NULL);
|
||||
void syncSize(Container & c, JsonNode::JsonType type = JsonNode::JsonType::DATA_NULL);
|
||||
|
||||
///vector of serializable <-> Json vector of structs
|
||||
template <typename Element>
|
||||
void serializeStruct(std::vector<Element> & value)
|
||||
{
|
||||
syncSize(value, JsonNode::DATA_STRUCT);
|
||||
syncSize(value, JsonNode::JsonType::DATA_STRUCT);
|
||||
|
||||
for(size_t idx = 0; idx < size(); idx++)
|
||||
{
|
||||
|
@ -61,7 +61,7 @@ void JsonSerializer::serializeInternal(const std::string & fieldName, std::vecto
|
||||
|
||||
for(const si32 rawId : value)
|
||||
{
|
||||
JsonNode jsonElement(JsonNode::DATA_STRING);
|
||||
JsonNode jsonElement(JsonNode::JsonType::DATA_STRING);
|
||||
jsonElement.String() = encoder(rawId);
|
||||
data.push_back(std::move(jsonElement));
|
||||
}
|
||||
@ -133,7 +133,7 @@ void JsonSerializer::writeLICPartBuffer(const std::string & fieldName, const std
|
||||
|
||||
for(auto & s : buffer)
|
||||
{
|
||||
JsonNode val(JsonNode::DATA_STRING);
|
||||
JsonNode val(JsonNode::JsonType::DATA_STRING);
|
||||
std::swap(val.String(), s);
|
||||
target.push_back(std::move(val));
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ ESpellCastResult TownPortalMechanics::beginCast(const SpellCastEnvironment * env
|
||||
{
|
||||
auto queryCallback = [=](const JsonNode & reply) -> void
|
||||
{
|
||||
if(reply.getType() == JsonNode::DATA_INTEGER)
|
||||
if(reply.getType() == JsonNode::JsonType::DATA_INTEGER)
|
||||
{
|
||||
ObjectInstanceID townId(reply.Integer());
|
||||
|
||||
|
@ -708,7 +708,7 @@ std::vector<JsonNode> CSpellHandler::loadLegacyData(size_t dataSize)
|
||||
{
|
||||
do
|
||||
{
|
||||
JsonNode lineNode(JsonNode::DATA_STRUCT);
|
||||
JsonNode lineNode(JsonNode::JsonType::DATA_STRUCT);
|
||||
|
||||
const si32 id = legacyData.size();
|
||||
|
||||
@ -951,9 +951,9 @@ CSpell * CSpellHandler::loadFromJson(const JsonNode & json, const std::string &
|
||||
{
|
||||
CSpell::TAnimation newItem;
|
||||
|
||||
if(item.getType() == JsonNode::DATA_STRING)
|
||||
if(item.getType() == JsonNode::JsonType::DATA_STRING)
|
||||
newItem.resourceName = item.String();
|
||||
else if(item.getType() == JsonNode::DATA_STRUCT)
|
||||
else if(item.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
newItem.resourceName = item["defName"].String();
|
||||
|
||||
|
@ -426,7 +426,7 @@ bool CDialogQuery::blocksPack(const CPack * pack) const
|
||||
|
||||
void CDialogQuery::setReply(const JsonNode & reply)
|
||||
{
|
||||
if(reply.getType() == JsonNode::DATA_INTEGER)
|
||||
if(reply.getType() == JsonNode::JsonType::DATA_INTEGER)
|
||||
answer = reply.Integer();
|
||||
}
|
||||
|
||||
|
@ -305,17 +305,17 @@ bool JsonMapComparer::isEmpty(const JsonNode & value)
|
||||
{
|
||||
switch (value.getType())
|
||||
{
|
||||
case JsonNode::DATA_NULL:
|
||||
case JsonNode::JsonType::DATA_NULL:
|
||||
return true;
|
||||
case JsonNode::DATA_BOOL:
|
||||
case JsonNode::JsonType::DATA_BOOL:
|
||||
return !value.Bool();
|
||||
case JsonNode::DATA_FLOAT:
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
return value.Float() == 0;
|
||||
case JsonNode::DATA_STRING:
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
return value.String() == "";
|
||||
case JsonNode::DATA_VECTOR:
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
return value.Vector().empty();
|
||||
case JsonNode::DATA_STRUCT:
|
||||
case JsonNode::JsonType::DATA_STRUCT:
|
||||
return value.Struct().empty();
|
||||
break;
|
||||
default:
|
||||
@ -392,24 +392,24 @@ void JsonMapComparer::checkEqualJson(const JsonNode & actual, const JsonNode & e
|
||||
{
|
||||
switch (actual.getType())
|
||||
{
|
||||
case JsonNode::DATA_NULL:
|
||||
case JsonNode::JsonType::DATA_NULL:
|
||||
break; //do nothing
|
||||
case JsonNode::DATA_BOOL:
|
||||
case JsonNode::JsonType::DATA_BOOL:
|
||||
check(actual.Bool() == expected.Bool(), "mismatch");
|
||||
break;
|
||||
case JsonNode::DATA_FLOAT:
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
checkEqualFloat(actual.Float(),expected.Float());
|
||||
break;
|
||||
case JsonNode::DATA_STRING:
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
checkEqualString(actual.String(),expected.String());
|
||||
break;
|
||||
case JsonNode::DATA_VECTOR:
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
checkEqualJson(actual.Vector(), expected.Vector());
|
||||
break;
|
||||
case JsonNode::DATA_STRUCT:
|
||||
case JsonNode::JsonType::DATA_STRUCT:
|
||||
checkEqualJson(actual.Struct(), expected.Struct());
|
||||
break;
|
||||
case JsonNode::DATA_INTEGER:
|
||||
case JsonNode::JsonType::DATA_INTEGER:
|
||||
checkEqualInteger(actual.Integer(), expected.Integer());
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user