1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Reworked JsonNode constructors to more logical form

This commit is contained in:
Ivan Savenko 2024-02-13 13:18:10 +02:00
parent 54796c7c56
commit 08a27663f9
25 changed files with 125 additions and 161 deletions

View File

@ -102,7 +102,7 @@ void CAnimation::initFromJson(const JsonNode & config)
std::string basepath;
basepath = config["basepath"].String();
JsonNode base(JsonNode::JsonType::DATA_STRUCT);
JsonNode base;
base["margins"] = config["margins"];
base["width"] = config["width"];
base["height"] = config["height"];
@ -114,7 +114,7 @@ void CAnimation::initFromJson(const JsonNode & config)
for(const JsonNode & frame : group["frames"].Vector())
{
JsonNode toAdd(JsonNode::JsonType::DATA_STRUCT);
JsonNode toAdd;
JsonUtils::inherit(toAdd, base);
toAdd["file"].String() = basepath + frame.String();
source[groupID].push_back(toAdd);
@ -129,7 +129,7 @@ void CAnimation::initFromJson(const JsonNode & config)
if (source[group].size() <= frame)
source[group].resize(frame+1);
JsonNode toAdd(JsonNode::JsonType::DATA_STRUCT);
JsonNode toAdd;
JsonUtils::inherit(toAdd, base);
toAdd["file"].String() = basepath + node["file"].String();
source[group][frame] = toAdd;
@ -191,7 +191,7 @@ void CAnimation::init()
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
stream->read(textData.get(), stream->getSize());
const JsonNode config((char*)textData.get(), stream->getSize());
const JsonNode config(reinterpret_cast<const std::byte*>(textData.get()), stream->getSize());
initFromJson(config);
}

View File

@ -107,7 +107,7 @@ void Graphics::initializeBattleGraphics()
if(!CResourceHandler::get(mod)->existsResource(ResourcePath("config/battles_graphics.json")))
continue;
const JsonNode config(mod, JsonPath::builtin("config/battles_graphics.json"));
const JsonNode config(JsonPath::builtin("config/battles_graphics.json"), mod);
//initialization of AC->def name mapping
if(!config["ac_mapping"].isNull())

View File

@ -89,7 +89,7 @@ QVariant JsonFromFile(QString filename)
}
const auto data = file.readAll();
JsonNode node(data.data(), data.size());
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size());
return toVariant(node);
}

View File

@ -67,7 +67,7 @@ UpdateDialog::UpdateDialog(bool calledManually, QWidget *parent):
}
auto byteArray = response->readAll();
JsonNode node(byteArray.constData(), byteArray.size());
JsonNode node(reinterpret_cast<const std::byte*>(byteArray.constData()), byteArray.size());
loadFromJson(node);
});
}

View File

@ -168,7 +168,7 @@ std::vector<JsonNode> CSkillHandler::loadLegacyData()
std::vector<JsonNode> legacyData;
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
{
JsonNode skillNode(JsonNode::JsonType::DATA_STRUCT);
JsonNode skillNode;
skillNode["name"].String() = skillNames[id];
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
{

View File

@ -26,7 +26,6 @@
#include "../TerrainHandler.h"
#include "../constants/StringConstants.h"
#include "../battle/BattleInfo.h"
#include "../json/JsonUtils.h"
#include "../modding/ModUtility.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -79,13 +78,13 @@ JsonNode CAddInfo::toJsonNode() const
{
if(size() < 2)
{
return JsonUtils::intNode(operator[](0));
return JsonNode(operator[](0));
}
else
{
JsonNode node(JsonNode::JsonType::DATA_VECTOR);
JsonNode node;
for(si32 value : *this)
node.Vector().push_back(JsonUtils::intNode(value));
node.Vector().emplace_back(value);
return node;
}
}
@ -143,7 +142,7 @@ static JsonNode additionalInfoToJson(BonusType type, CAddInfo addInfo)
switch(type)
{
case BonusType::SPECIAL_UPGRADE:
return JsonUtils::stringNode(ModUtility::makeFullIdentifier("", "creature", CreatureID::encode(addInfo[0])));
return JsonNode(ModUtility::makeFullIdentifier("", "creature", CreatureID::encode(addInfo[0])));
default:
return addInfo.toJsonNode();
}
@ -151,7 +150,7 @@ static JsonNode additionalInfoToJson(BonusType type, CAddInfo addInfo)
JsonNode Bonus::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
// only add values that might reasonably be found in config files
root["type"].String() = vstd::findKey(bonusNameMap, type);
if(subtype != BonusSubtypeID())

View File

@ -67,13 +67,13 @@ namespace BonusDuration
}
if(durationNames.size() == 1)
{
return JsonUtils::stringNode(durationNames[0]);
return JsonNode(durationNames[0]);
}
else
{
JsonNode node(JsonNode::JsonType::DATA_VECTOR);
JsonNode node;
for(const std::string & dur : durationNames)
node.Vector().push_back(JsonUtils::stringNode(dur));
node.Vector().emplace_back(dur);
return node;
}
}

View File

@ -213,7 +213,7 @@ int BonusList::valOfBonuses(const CSelector &select) const
JsonNode BonusList::toJsonNode() const
{
JsonNode node(JsonNode::JsonType::DATA_VECTOR);
JsonNode node;
for(const std::shared_ptr<Bonus> & b : bonuses)
node.Vector().push_back(b->toJsonNode());
return node;

View File

@ -92,7 +92,7 @@ std::string ILimiter::toString() const
JsonNode ILimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = toString();
return root;
}
@ -127,11 +127,11 @@ std::string CCreatureTypeLimiter::toString() const
JsonNode CCreatureTypeLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "CREATURE_TYPE_LIMITER";
root["parameters"].Vector().push_back(JsonUtils::stringNode(creature->getJsonKey()));
root["parameters"].Vector().push_back(JsonUtils::boolNode(includeUpgrades));
root["parameters"].Vector().emplace_back(creature->getJsonKey());
root["parameters"].Vector().emplace_back(includeUpgrades);
return root;
}
@ -199,16 +199,16 @@ std::string HasAnotherBonusLimiter::toString() const
JsonNode HasAnotherBonusLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
std::string typeName = vstd::findKey(bonusNameMap, type);
auto sourceTypeName = vstd::findKey(bonusSourceMap, source);
root["type"].String() = "HAS_ANOTHER_BONUS_LIMITER";
root["parameters"].Vector().push_back(JsonUtils::stringNode(typeName));
root["parameters"].Vector().emplace_back(typeName);
if(isSubtypeRelevant)
root["parameters"].Vector().push_back(JsonUtils::stringNode(subtype.toString()));
root["parameters"].Vector().emplace_back(subtype.toString());
if(isSourceRelevant)
root["parameters"].Vector().push_back(JsonUtils::stringNode(sourceTypeName));
root["parameters"].Vector().emplace_back(sourceTypeName);
return root;
}
@ -233,11 +233,11 @@ UnitOnHexLimiter::UnitOnHexLimiter(const std::set<BattleHex> & applicableHexes):
JsonNode UnitOnHexLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "UNIT_ON_HEXES";
for(const auto & hex : applicableHexes)
root["parameters"].Vector().push_back(JsonUtils::intNode(hex));
root["parameters"].Vector().emplace_back(hex);
return root;
}
@ -278,11 +278,11 @@ std::string CreatureTerrainLimiter::toString() const
JsonNode CreatureTerrainLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "CREATURE_TERRAIN_LIMITER";
auto terrainName = VLC->terrainTypeHandler->getById(terrainType)->getJsonKey();
root["parameters"].Vector().push_back(JsonUtils::stringNode(terrainName));
root["parameters"].Vector().emplace_back(terrainName);
return root;
}
@ -324,10 +324,10 @@ std::string FactionLimiter::toString() const
JsonNode FactionLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "FACTION_LIMITER";
root["parameters"].Vector().push_back(JsonUtils::stringNode(VLC->factions()->getById(faction)->getJsonKey()));
root["parameters"].Vector().emplace_back(VLC->factions()->getById(faction)->getJsonKey());
return root;
}
@ -354,11 +354,11 @@ std::string CreatureLevelLimiter::toString() const
JsonNode CreatureLevelLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "CREATURE_LEVEL_LIMITER";
root["parameters"].Vector().push_back(JsonUtils::intNode(minLevel));
root["parameters"].Vector().push_back(JsonUtils::intNode(maxLevel));
root["parameters"].Vector().emplace_back(minLevel);
root["parameters"].Vector().emplace_back(maxLevel);
return root;
}
@ -392,10 +392,10 @@ std::string CreatureAlignmentLimiter::toString() const
JsonNode CreatureAlignmentLimiter::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "CREATURE_ALIGNMENT_LIMITER";
root["parameters"].Vector().push_back(JsonUtils::stringNode(GameConstants::ALIGNMENT_NAMES[vstd::to_underlying(alignment)]));
root["parameters"].Vector().emplace_back(GameConstants::ALIGNMENT_NAMES[vstd::to_underlying(alignment)]);
return root;
}
@ -450,8 +450,8 @@ void AggregateLimiter::add(const TLimiterPtr & limiter)
JsonNode AggregateLimiter::toJsonNode() const
{
JsonNode result(JsonNode::JsonType::DATA_VECTOR);
result.Vector().push_back(JsonUtils::stringNode(getAggregator()));
JsonNode result;
result.Vector().emplace_back(getAggregator());
for(const auto & l : limiters)
result.Vector().push_back(l->toJsonNode());
return result;

View File

@ -13,7 +13,7 @@
#include "Updaters.h"
#include "Limiters.h"
#include "../json/JsonUtils.h"
#include "../json/JsonNode.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../CStack.h"
@ -39,7 +39,7 @@ std::string IUpdater::toString() const
JsonNode IUpdater::toJsonNode() const
{
return JsonNode(JsonNode::JsonType::DATA_NULL);
return JsonNode();
}
GrowsWithLevelUpdater::GrowsWithLevelUpdater(int valPer20, int stepSize) : valPer20(valPer20), stepSize(stepSize)
@ -69,12 +69,12 @@ std::string GrowsWithLevelUpdater::toString() const
JsonNode GrowsWithLevelUpdater::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "GROWS_WITH_LEVEL";
root["parameters"].Vector().push_back(JsonUtils::intNode(valPer20));
root["parameters"].Vector().emplace_back(valPer20);
if(stepSize > 1)
root["parameters"].Vector().push_back(JsonUtils::intNode(stepSize));
root["parameters"].Vector().emplace_back(stepSize);
return root;
}
@ -98,7 +98,7 @@ std::string TimesHeroLevelUpdater::toString() const
JsonNode TimesHeroLevelUpdater::toJsonNode() const
{
return JsonUtils::stringNode("TIMES_HERO_LEVEL");
return JsonNode("TIMES_HERO_LEVEL");
}
ArmyMovementUpdater::ArmyMovementUpdater():
@ -141,13 +141,13 @@ std::string ArmyMovementUpdater::toString() const
JsonNode ArmyMovementUpdater::toJsonNode() const
{
JsonNode root(JsonNode::JsonType::DATA_STRUCT);
JsonNode root;
root["type"].String() = "ARMY_MOVEMENT";
root["parameters"].Vector().push_back(JsonUtils::intNode(base));
root["parameters"].Vector().push_back(JsonUtils::intNode(divider));
root["parameters"].Vector().push_back(JsonUtils::intNode(multiplier));
root["parameters"].Vector().push_back(JsonUtils::intNode(max));
root["parameters"].Vector().emplace_back(base);
root["parameters"].Vector().emplace_back(divider);
root["parameters"].Vector().emplace_back(multiplier);
root["parameters"].Vector().emplace_back(max);
return root;
}
@ -183,7 +183,7 @@ std::string TimesStackLevelUpdater::toString() const
JsonNode TimesStackLevelUpdater::toJsonNode() const
{
return JsonUtils::stringNode("TIMES_STACK_LEVEL");
return JsonNode("TIMES_STACK_LEVEL");
}
std::string OwnerUpdater::toString() const
@ -193,7 +193,7 @@ std::string OwnerUpdater::toString() const
JsonNode OwnerUpdater::toJsonNode() const
{
return JsonUtils::stringNode("BONUS_OWNER_UPDATER");
return JsonNode("BONUS_OWNER_UPDATER");
}
std::shared_ptr<Bonus> OwnerUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const

View File

@ -46,7 +46,7 @@ void CampaignHandler::readCampaign(Campaign * ret, const std::vector<ui8> & inpu
}
else // text format (json)
{
JsonNode jsonCampaign((const char*)input.data(), input.size());
JsonNode jsonCampaign(reinterpret_cast<const std::byte*>(input.data()), input.size());
readHeaderFromJson(*ret, jsonCampaign, filename, modName, encoding);
for(auto & scenario : jsonCampaign["scenarios"].Vector())

View File

@ -117,7 +117,7 @@ void CFilesystemGenerator::loadJsonMap(const std::string &mountPoint, const Json
if (filename)
{
auto configData = CResourceHandler::get("initial")->load(JsonPath::builtin(URI))->readAll();
const JsonNode configInitial(reinterpret_cast<char *>(configData.first.get()), configData.second);
const JsonNode configInitial(reinterpret_cast<std::byte *>(configData.first.get()), configData.second);
filesystem->addLoader(new CMappedFileLoader(mountPoint, configInitial), false);
}
}
@ -212,7 +212,7 @@ void CResourceHandler::load(const std::string &fsConfigURI, bool extractArchives
{
auto fsConfigData = get("initial")->load(JsonPath::builtin(fsConfigURI))->readAll();
const JsonNode fsConfig(reinterpret_cast<char *>(fsConfigData.first.get()), fsConfigData.second);
const JsonNode fsConfig(reinterpret_cast<std::byte *>(fsConfigData.first.get()), fsConfigData.second);
addFilesystem("data", ModScope::scopeBuiltin(), createFileSystem("", fsConfig["filesystem"], extractArchives));
}

View File

@ -56,18 +56,33 @@ class CModHandler;
static const JsonNode nullNode;
JsonNode::JsonNode(JsonType Type)
{
setType(Type);
}
JsonNode::JsonNode(const std::byte *data, size_t datasize)
:JsonNode(reinterpret_cast<const char*>(data), datasize)
JsonNode::JsonNode(bool boolean)
:data(boolean)
{}
JsonNode::JsonNode(const char *data, size_t datasize)
JsonNode::JsonNode(int32_t number)
:data(static_cast<int64_t>(number))
{}
JsonNode::JsonNode(uint32_t number)
:data(static_cast<int64_t>(number))
{}
JsonNode::JsonNode(int64_t number)
:data(number)
{}
JsonNode::JsonNode(double number)
:data(number)
{}
JsonNode::JsonNode(const std::string & string)
:data(string)
{}
JsonNode::JsonNode(const std::byte *data, size_t datasize)
{
JsonParser parser(data, datasize);
JsonParser parser(reinterpret_cast<const char*>(data), datasize);
*this = parser.parse("<unknown>");
}
@ -79,7 +94,7 @@ JsonNode::JsonNode(const JsonPath & fileURI)
*this = parser.parse(fileURI.getName());
}
JsonNode::JsonNode(const std::string & idx, const JsonPath & fileURI)
JsonNode::JsonNode(const JsonPath & fileURI, const std::string & idx)
{
auto file = CResourceHandler::get(idx)->load(fileURI)->readAll();

View File

@ -37,24 +37,32 @@ public:
};
private:
using JsonData = std::variant<std::monostate, bool, double, std::string, JsonVector, JsonMap, si64>;
using JsonData = std::variant<std::monostate, bool, double, std::string, JsonVector, JsonMap, int64_t>;
JsonData data;
public:
/// free to use metadata fields
std::string meta;
// meta-flags like override
/// meta-flags like override
std::vector<std::string> flags;
//Create empty node
JsonNode(JsonType Type = JsonType::DATA_NULL);
//Create tree from Json-formatted input
explicit JsonNode(const char * data, size_t datasize);
JsonNode() = default;
/// Create single node with specified value
explicit JsonNode(bool boolean);
explicit JsonNode(int32_t number);
explicit JsonNode(uint32_t number);
explicit JsonNode(int64_t number);
explicit JsonNode(double number);
explicit JsonNode(const std::string & string);
/// Create tree from Json-formatted input
explicit JsonNode(const std::byte * data, size_t datasize);
//Create tree from JSON file
/// Create tree from JSON file
explicit JsonNode(const JsonPath & fileURI);
explicit JsonNode(const std::string & modName, const JsonPath & fileURI);
explicit JsonNode(const JsonPath & fileURI, const std::string & modName);
explicit JsonNode(const JsonPath & fileURI, bool & isValidSyntax);
bool operator == (const JsonNode &other) const;

View File

@ -273,7 +273,7 @@ JsonNode JsonUtils::intersect(const JsonNode & a, const JsonNode & b, bool prune
if(a.getType() == JsonNode::JsonType::DATA_STRUCT && b.getType() == JsonNode::JsonType::DATA_STRUCT)
{
// intersect individual properties
JsonNode result(JsonNode::JsonType::DATA_STRUCT);
JsonNode result;
for(const auto & property : a.Struct())
{
if(vstd::contains(b.Struct(), property.first))
@ -313,7 +313,7 @@ JsonNode JsonUtils::difference(const JsonNode & node, const JsonNode & base)
if(node.getType() == JsonNode::JsonType::DATA_STRUCT && base.getType() == JsonNode::JsonType::DATA_STRUCT)
{
// subtract individual properties
JsonNode result(JsonNode::JsonType::DATA_STRUCT);
JsonNode result;
for(const auto & property : node.Struct())
{
if(vstd::contains(base.Struct(), property.first))
@ -370,38 +370,10 @@ JsonNode JsonUtils::assembleFromFiles(const std::string & filename)
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
stream->read(textData.get(), stream->getSize());
JsonNode section(reinterpret_cast<char *>(textData.get()), stream->getSize());
JsonNode section(reinterpret_cast<std::byte *>(textData.get()), stream->getSize());
merge(result, section);
}
return result;
}
DLL_LINKAGE JsonNode JsonUtils::boolNode(bool value)
{
JsonNode node;
node.Bool() = value;
return node;
}
DLL_LINKAGE JsonNode JsonUtils::floatNode(double value)
{
JsonNode node;
node.Float() = value;
return node;
}
DLL_LINKAGE JsonNode JsonUtils::stringNode(const std::string & value)
{
JsonNode node;
node.String() = value;
return node;
}
DLL_LINKAGE JsonNode JsonUtils::intNode(si64 value)
{
JsonNode node;
node.Integer() = value;
return node;
}
VCMI_LIB_NAMESPACE_END

View File

@ -88,12 +88,6 @@ namespace JsonUtils
/// get schema by json URI: vcmi:<name of file in schemas directory>#<entry in file, optional>
/// example: schema "vcmi:settings" is used to check user settings
DLL_LINKAGE const JsonNode & getSchema(const std::string & URI);
/// for easy construction of JsonNodes; helps with inserting primitives into vector node
DLL_LINKAGE JsonNode boolNode(bool value);
DLL_LINKAGE JsonNode floatNode(double value);
DLL_LINKAGE JsonNode stringNode(const std::string & value);
DLL_LINKAGE JsonNode intNode(si64 value);
}
VCMI_LIB_NAMESPACE_END

View File

@ -220,13 +220,10 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
{
if(handler.saving)
{
JsonNode node(JsonNode::JsonType::DATA_VECTOR);
JsonNode node;
for(const auto & resID : abandonedMineResources)
{
JsonNode one(JsonNode::JsonType::DATA_STRING);
one.String() = GameConstants::RESOURCE_NAMES[resID.getNum()];
node.Vector().push_back(one);
}
node.Vector().emplace_back(GameConstants::RESOURCE_NAMES[resID.getNum()]);
handler.serializeRaw("possibleResources", node, std::nullopt);
}
else

View File

@ -354,11 +354,7 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
JsonVector & data = node["allowedTerrains"].Vector();
for(auto type : allowedTerrains)
{
JsonNode value(JsonNode::JsonType::DATA_STRING);
value.String() = VLC->terrainTypeHandler->getById(type)->getJsonKey();
data.push_back(value);
}
data.push_back(JsonNode(VLC->terrainTypeHandler->getById(type)->getJsonKey()));
}
}
@ -398,13 +394,11 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
for(size_t i=0; i < height; i++)
{
JsonNode lineNode(JsonNode::JsonType::DATA_STRING);
std::string & line = lineNode.String();
std::string line;
line.resize(width);
for(size_t j=0; j < width; j++)
line[j] = tileToChar(usedTiles[height - 1 - i][width - 1 - j]);
mask.push_back(lineNode);
mask.emplace_back(line);
}
if(printPriority != 0)

View File

@ -545,13 +545,10 @@ void CMapFormatJson::writeTeams(JsonSerializer & handler)
for(const std::set<PlayerColor> & teamData : teamsData)
{
JsonNode team(JsonNode::JsonType::DATA_VECTOR);
JsonNode team;
for(const PlayerColor & player : teamData)
{
JsonNode member(JsonNode::JsonType::DATA_STRING);
member.String() = GameConstants::PLAYER_COLOR_NAMES[player.getNum()];
team.Vector().push_back(std::move(member));
}
team.Vector().emplace_back(GameConstants::PLAYER_COLOR_NAMES[player.getNum()]);
dest.Vector().push_back(std::move(team));
}
handler.serializeRaw("teams", dest, std::nullopt);
@ -586,7 +583,7 @@ void CMapFormatJson::readTriggeredEvent(TriggeredEvent & event, const JsonNode &
void CMapFormatJson::writeTriggeredEvents(JsonSerializer & handler)
{
JsonNode triggeredEvents(JsonNode::JsonType::DATA_STRUCT);
JsonNode triggeredEvents;
for(const auto & event : mapHeader->triggeredEvents)
writeTriggeredEvent(event, triggeredEvents[event.identifier]);
@ -657,7 +654,7 @@ void CMapFormatJson::writeDisposedHeroes(JsonSerializeFormat & handler)
auto definition = definitions->enterStruct(type);
JsonNode players(JsonNode::JsonType::DATA_VECTOR);
JsonNode players;
definition->serializeIdArray("availableFor", hero.players);
}
}
@ -812,7 +809,7 @@ JsonNode CMapLoaderJson::getFromArchive(const std::string & archiveFilename)
auto data = loader.load(resource)->readAll();
JsonNode res(reinterpret_cast<char*>(data.first.get()), data.second);
JsonNode res(reinterpret_cast<const std::byte*>(data.first.get()), data.second);
return res;
}
@ -1329,7 +1326,7 @@ void CMapSaverJson::writeTerrain()
void CMapSaverJson::writeObjects()
{
logGlobal->trace("Saving objects");
JsonNode data(JsonNode::JsonType::DATA_STRUCT);
JsonNode data;
JsonSerializer handler(mapObjectResolver.get(), data);
@ -1343,7 +1340,7 @@ void CMapSaverJson::writeObjects()
if(map->grailPos.valid())
{
JsonNode grail(JsonNode::JsonType::DATA_STRUCT);
JsonNode grail;
grail["type"].String() = "grail";
grail["x"].Float() = map->grailPos.x;

View File

@ -60,11 +60,7 @@ void JsonSerializer::serializeInternal(const std::string & fieldName, std::vecto
data.reserve(value.size());
for(const si32 rawId : value)
{
JsonNode jsonElement(JsonNode::JsonType::DATA_STRING);
jsonElement.String() = encoder(rawId);
data.push_back(std::move(jsonElement));
}
data.emplace_back(rawId);
}
void JsonSerializer::serializeInternal(const std::string & fieldName, std::vector<std::string> & value)
@ -76,11 +72,7 @@ void JsonSerializer::serializeInternal(const std::string & fieldName, std::vecto
data.reserve(value.size());
for(const auto & rawId : value)
{
JsonNode jsonElement(JsonNode::JsonType::DATA_STRING);
jsonElement.String() = rawId;
data.push_back(std::move(jsonElement));
}
data.emplace_back(rawId);
}
void JsonSerializer::serializeInternal(std::string & value)
@ -183,11 +175,7 @@ void JsonSerializer::writeLICPartBuffer(const std::string & fieldName, const std
auto & target = currentObject->operator[](fieldName)[partName].Vector();
for(auto & s : buffer)
{
JsonNode val(JsonNode::JsonType::DATA_STRING);
std::swap(val.String(), s);
target.push_back(std::move(val));
}
target.emplace_back(s);
}
}

View File

@ -582,7 +582,7 @@ std::vector<JsonNode> CSpellHandler::loadLegacyData()
{
do
{
JsonNode lineNode(JsonNode::JsonType::DATA_STRUCT);
JsonNode lineNode;
const auto id = legacyData.size();

View File

@ -58,7 +58,7 @@ NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID) c
void LobbyServer::sendMessage(const NetworkConnectionPtr & target, const JsonNode & json)
{
target->sendPacket(json.toBytes(true));
target->sendPacket(json.toBytes());
}
void LobbyServer::sendAccountCreated(const NetworkConnectionPtr & target, const std::string & accountID, const std::string & accountCookie)

View File

@ -599,7 +599,7 @@ void Animation::init()
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
stream->read(textData.get(), stream->getSize());
const JsonNode config((char*)textData.get(), stream->getSize());
const JsonNode config(reinterpret_cast<const std::byte*>(textData.get()), stream->getSize());
initFromJson(config);
}
@ -610,7 +610,7 @@ void Animation::initFromJson(const JsonNode & config)
std::string basepath;
basepath = config["basepath"].String();
JsonNode base(JsonNode::JsonType::DATA_STRUCT);
JsonNode base;
base["margins"] = config["margins"];
base["width"] = config["width"];
base["height"] = config["height"];
@ -622,7 +622,7 @@ void Animation::initFromJson(const JsonNode & config)
for(const JsonNode & frame : group["frames"].Vector())
{
JsonNode toAdd(JsonNode::JsonType::DATA_STRUCT);
JsonNode toAdd;
JsonUtils::inherit(toAdd, base);
toAdd["file"].String() = basepath + frame.String();
source[groupID].push_back(toAdd);
@ -637,7 +637,7 @@ void Animation::initFromJson(const JsonNode & config)
if (source[group].size() <= frame)
source[group].resize(frame+1);
JsonNode toAdd(JsonNode::JsonType::DATA_STRUCT);
JsonNode toAdd;
JsonUtils::inherit(toAdd, base);
toAdd["file"].String() = basepath + node["file"].String();
source[group][frame] = toAdd;

View File

@ -96,7 +96,7 @@ QVariant JsonFromFile(QString filename)
}
else
{
JsonNode node(data.data(), data.size());
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size());
return toVariant(node);
}
}

View File

@ -24,7 +24,7 @@ void Translations::cleanupRemovedItems(CMap & map)
for(auto & translations : map.translations.Struct())
{
auto updateTranslations = JsonNode(JsonNode::JsonType::DATA_STRUCT);
JsonNode updateTranslations;
for(auto & s : translations.second.Struct())
{
for(auto part : QString::fromStdString(s.first).split('.'))
@ -44,7 +44,7 @@ void Translations::cleanupRemovedItems(CMap & map, const std::string & pattern)
{
for(auto & translations : map.translations.Struct())
{
auto updateTranslations = JsonNode(JsonNode::JsonType::DATA_STRUCT);
JsonNode updateTranslations;
for(auto & s : translations.second.Struct())
{
if(s.first.find(pattern) == std::string::npos)
@ -171,7 +171,7 @@ void Translations::on_supportedCheck_toggled(bool checked)
}
ui->translationsTable->blockSignals(true);
ui->translationsTable->setRowCount(0);
translation = JsonNode(JsonNode::JsonType::DATA_NULL);
translation.clear();
ui->translationsTable->blockSignals(false);
ui->translationsTable->setEnabled(false);
}