mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Moved serialization of ModCompatibilityInfo from MapFormat
This commit is contained in:
parent
62d15ed23c
commit
6ba6e0d55b
@ -145,6 +145,7 @@ set(lib_MAIN_SRCS
|
||||
modding/ContentTypeHandler.cpp
|
||||
modding/IdentifierStorage.cpp
|
||||
modding/ModUtility.cpp
|
||||
modding/ModVerificationInfo.cpp
|
||||
|
||||
networkPacks/NetPacksLib.cpp
|
||||
|
||||
|
@ -23,7 +23,6 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class CGObjectInstance;
|
||||
enum class EMapFormat : uint8_t;
|
||||
using ModCompatibilityInfo = std::map<std::string, ModVerificationInfo>;
|
||||
|
||||
/// The hero name struct consists of the hero id and the hero name.
|
||||
struct DLL_LINKAGE SHeroName
|
||||
|
@ -24,8 +24,6 @@ class IMapLoader;
|
||||
class IMapPatcher;
|
||||
class IGameCallback;
|
||||
|
||||
using ModCompatibilityInfo = std::map<std::string, ModVerificationInfo>;
|
||||
|
||||
/**
|
||||
* The map service provides loading of VCMI/H3 map files. It can
|
||||
* be extended to save maps later as well.
|
||||
|
@ -850,23 +850,7 @@ void CMapLoaderJson::readHeader(const bool complete)
|
||||
mapHeader->version = EMapFormat::VCMI;//todo: new version field
|
||||
|
||||
//loading mods
|
||||
if(!header["mods"].isNull())
|
||||
{
|
||||
for(auto & mod : header["mods"].Vector())
|
||||
{
|
||||
ModVerificationInfo info;
|
||||
info.version = CModVersion::fromString(mod["version"].String());
|
||||
info.checksum = mod["checksum"].Integer();
|
||||
info.name = mod["name"].String();
|
||||
info.parent = mod["parent"].String();
|
||||
info.impactsGameplay = true;
|
||||
|
||||
if(!mod["modId"].isNull())
|
||||
mapHeader->mods[mod["modId"].String()] = info;
|
||||
else
|
||||
mapHeader->mods[mod["name"].String()] = info;
|
||||
}
|
||||
}
|
||||
mapHeader->mods = ModVerificationInfo::jsonDeserializeList(header["mods"]);
|
||||
|
||||
//todo: multilevel map load support
|
||||
{
|
||||
@ -1231,17 +1215,7 @@ void CMapSaverJson::writeHeader()
|
||||
header["versionMinor"].Float() = VERSION_MINOR;
|
||||
|
||||
//write mods
|
||||
JsonNode & mods = header["mods"];
|
||||
for(const auto & mod : mapHeader->mods)
|
||||
{
|
||||
JsonNode modWriter;
|
||||
modWriter["modId"].String() = mod.first;
|
||||
modWriter["name"].String() = mod.second.name;
|
||||
modWriter["parent"].String() = mod.second.parent;
|
||||
modWriter["version"].String() = mod.second.version.toString();
|
||||
modWriter["checksum"].Integer() = mod.second.checksum;
|
||||
mods.Vector().push_back(modWriter);
|
||||
}
|
||||
header["mods"] = ModVerificationInfo::jsonSerializeList(mapHeader->mods);
|
||||
|
||||
//todo: multilevel map save support
|
||||
JsonNode & levels = header["mapLevels"];
|
||||
|
52
lib/modding/ModVerificationInfo.cpp
Normal file
52
lib/modding/ModVerificationInfo.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* ModVerificationInfo.cpp, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
* License: GNU General Public License v2.0 or later
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "ModVerificationInfo.h"
|
||||
|
||||
#include "../json/JsonNode.h"
|
||||
|
||||
JsonNode ModVerificationInfo::jsonSerializeList(const ModCompatibilityInfo & input)
|
||||
{
|
||||
JsonNode output;
|
||||
|
||||
for(const auto & mod : input)
|
||||
{
|
||||
JsonNode modWriter;
|
||||
modWriter["modId"].String() = mod.first;
|
||||
modWriter["name"].String() = mod.second.name;
|
||||
modWriter["parent"].String() = mod.second.parent;
|
||||
modWriter["version"].String() = mod.second.version.toString();
|
||||
output.Vector().push_back(modWriter);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
ModCompatibilityInfo ModVerificationInfo::jsonDeserializeList(const JsonNode & input)
|
||||
{
|
||||
ModCompatibilityInfo output;
|
||||
|
||||
for(const auto & mod : input.Vector())
|
||||
{
|
||||
ModVerificationInfo info;
|
||||
info.version = CModVersion::fromString(mod["version"].String());
|
||||
info.name = mod["name"].String();
|
||||
info.parent = mod["parent"].String();
|
||||
info.checksum = 0;
|
||||
info.impactsGameplay = true;
|
||||
|
||||
if(!mod["modId"].isNull())
|
||||
output[mod["modId"].String()] = info;
|
||||
else
|
||||
output[mod["name"].String()] = info;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
@ -13,6 +13,10 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class JsonNode;
|
||||
struct ModVerificationInfo;
|
||||
using ModCompatibilityInfo = std::map<std::string, ModVerificationInfo>;
|
||||
|
||||
struct ModVerificationInfo
|
||||
{
|
||||
/// human-readable mod name
|
||||
@ -30,6 +34,9 @@ struct ModVerificationInfo
|
||||
/// for serialization purposes
|
||||
bool impactsGameplay = true;
|
||||
|
||||
static JsonNode jsonSerializeList(const ModCompatibilityInfo & input);
|
||||
static ModCompatibilityInfo jsonDeserializeList(const JsonNode & input);
|
||||
|
||||
template <typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user