2016-02-13 09:47:40 +02:00
|
|
|
/*
|
|
|
|
* JsonSerializeFormat.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 "JsonSerializeFormat.h"
|
|
|
|
|
|
|
|
#include "../JsonNode.h"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
//JsonSerializeHelper
|
2023-02-11 17:13:21 +02:00
|
|
|
JsonSerializeHelper::JsonSerializeHelper(JsonSerializeHelper && other) noexcept: owner(other.owner), restoreState(false)
|
2016-02-13 09:47:40 +02:00
|
|
|
{
|
2016-11-13 12:38:42 +02:00
|
|
|
std::swap(restoreState, other.restoreState);
|
2016-02-13 09:47:40 +02:00
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
JsonSerializeHelper::~JsonSerializeHelper()
|
2016-02-13 09:47:40 +02:00
|
|
|
{
|
|
|
|
if(restoreState)
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->pop();
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonSerializeFormat * JsonSerializeHelper::operator->()
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return owner;
|
2016-02-13 09:47:40 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
JsonSerializeHelper::JsonSerializeHelper(JsonSerializeFormat * owner_)
|
|
|
|
: owner(owner_),
|
2016-11-13 12:38:42 +02:00
|
|
|
restoreState(true)
|
2016-02-13 09:47:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
//JsonStructSerializer
|
2023-02-11 17:13:21 +02:00
|
|
|
JsonStructSerializer::JsonStructSerializer(JsonStructSerializer && other) noexcept: JsonSerializeHelper(std::move(static_cast<JsonSerializeHelper &>(other))) {}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
JsonStructSerializer::JsonStructSerializer(JsonSerializeFormat * owner_)
|
|
|
|
: JsonSerializeHelper(owner_)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//JsonArraySerializer
|
2023-02-11 17:13:21 +02:00
|
|
|
JsonArraySerializer::JsonArraySerializer(JsonArraySerializer && other) noexcept: JsonSerializeHelper(std::move(static_cast<JsonSerializeHelper &>(other))) {}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-02-11 17:13:21 +02:00
|
|
|
JsonArraySerializer::JsonArraySerializer(JsonSerializeFormat * owner_): JsonSerializeHelper(owner_), thisNode(&owner->getCurrent()) {}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
JsonStructSerializer JsonArraySerializer::enterStruct(const size_t index)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->pushArrayElement(index);
|
|
|
|
return JsonStructSerializer(owner);
|
2016-02-13 09:47:40 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
JsonArraySerializer JsonArraySerializer::enterArray(const size_t index)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->pushArrayElement(index);
|
|
|
|
return JsonArraySerializer(owner);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void JsonArraySerializer::serializeString(const size_t index, std::string & value)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->pushArrayElement(index);
|
|
|
|
owner->serializeInternal(value);
|
|
|
|
owner->pop();
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void JsonArraySerializer::serializeInt64(const size_t index, int64_t & value)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->pushArrayElement(index);
|
|
|
|
owner->serializeInternal(value);
|
|
|
|
owner->pop();
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArraySerializer::resize(const size_t newSize)
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
resize(newSize, JsonNode::JsonType::DATA_NULL);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void JsonArraySerializer::resize(const size_t newSize, JsonNode::JsonType type)
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->resizeCurrent(newSize, type);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t JsonArraySerializer::size() const
|
|
|
|
{
|
|
|
|
return thisNode->Vector().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//JsonSerializeFormat::LIC
|
2023-02-11 17:13:21 +02:00
|
|
|
JsonSerializeFormat::LIC::LIC(const std::vector<bool> & Standard, TDecoder Decoder, TEncoder Encoder):
|
|
|
|
standard(Standard),
|
|
|
|
decoder(std::move(Decoder)),
|
|
|
|
encoder(std::move(Encoder))
|
2016-02-23 15:36:21 +02:00
|
|
|
{
|
2016-02-25 21:59:17 +02:00
|
|
|
any.resize(standard.size(), false);
|
2016-02-23 15:36:21 +02:00
|
|
|
all.resize(standard.size(), false);
|
|
|
|
none.resize(standard.size(), false);
|
|
|
|
}
|
|
|
|
|
2023-02-11 17:13:21 +02:00
|
|
|
JsonSerializeFormat::LICSet::LICSet(const std::set<si32> & Standard, TDecoder Decoder, TEncoder Encoder):
|
|
|
|
standard(Standard),
|
|
|
|
decoder(std::move(Decoder)),
|
|
|
|
encoder(std::move(Encoder))
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2016-02-13 09:47:40 +02:00
|
|
|
|
|
|
|
//JsonSerializeFormat
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
JsonSerializeFormat::JsonSerializeFormat(const IInstanceResolver * instanceResolver_, const bool saving_, const bool updating_)
|
|
|
|
: saving(saving_),
|
|
|
|
updating(updating_),
|
2016-11-13 12:38:42 +02:00
|
|
|
instanceResolver(instanceResolver_)
|
2016-02-13 09:47:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonStructSerializer JsonSerializeFormat::enterStruct(const std::string & fieldName)
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
pushStruct(fieldName);
|
|
|
|
return JsonStructSerializer(this);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2016-02-13 09:47:40 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
JsonArraySerializer JsonSerializeFormat::enterArray(const std::string & fieldName)
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
pushArray(fieldName);
|
|
|
|
return JsonArraySerializer(this);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void JsonSerializeFormat::serializeBool(const std::string & fieldName, bool & value)
|
|
|
|
{
|
|
|
|
serializeBool<bool>(fieldName, value, true, false, false);
|
2016-02-13 09:47:40 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
void JsonSerializeFormat::serializeBool(const std::string & fieldName, bool & value, const bool defaultValue)
|
|
|
|
{
|
|
|
|
serializeBool<bool>(fieldName, value, true, false, defaultValue);
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|