1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/rewardable/Configuration.cpp

111 lines
3.2 KiB
C++
Raw Normal View History

2023-04-30 15:13:07 +02:00
/*
* Configuration.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
*
*/
2023-04-30 20:36:03 +02:00
#include "StdInc.h"
2023-04-30 15:13:07 +02:00
#include "Configuration.h"
2023-09-15 10:06:06 +02:00
#include "../serializer/JsonSerializeFormat.h"
2023-04-30 15:13:07 +02:00
VCMI_LIB_NAMESPACE_BEGIN
Rewardable::EVisitMode Rewardable::Configuration::getVisitMode() const
{
return static_cast<EVisitMode>(visitMode);
}
ui16 Rewardable::Configuration::getResetDuration() const
{
return resetParameters.period;
}
std::optional<int> Rewardable::Configuration::getVariable(const std::string & category, const std::string & name) const
{
std::string variableID = category + '@' + name;
if (variables.values.count(variableID))
return variables.values.at(variableID);
return std::nullopt;
}
const JsonNode & Rewardable::Configuration::getPresetVariable(const std::string & category, const std::string & name) const
{
static const JsonNode emptyNode;
std::string variableID = category + '@' + name;
if (variables.preset.count(variableID))
return variables.preset.at(variableID);
else
return emptyNode;
}
void Rewardable::Configuration::presetVariable(const std::string & category, const std::string & name, const JsonNode & value)
{
std::string variableID = category + '@' + name;
variables.preset[variableID] = value;
}
void Rewardable::Configuration::initVariable(const std::string & category, const std::string & name, int value)
{
std::string variableID = category + '@' + name;
variables.values[variableID] = value;
}
2023-09-15 10:06:06 +02:00
void Rewardable::ResetInfo::serializeJson(JsonSerializeFormat & handler)
{
handler.serializeInt("period", period);
handler.serializeBool("visitors", visitors);
handler.serializeBool("rewards", rewards);
}
void Rewardable::VisitInfo::serializeJson(JsonSerializeFormat & handler)
{
handler.serializeStruct("limiter", limiter);
handler.serializeStruct("reward", reward);
handler.serializeStruct("message", message);
handler.serializeInt("visitType", visitType);
}
void Rewardable::Variables::serializeJson(JsonSerializeFormat & handler)
{
2023-10-20 23:44:57 +02:00
if (handler.saving)
{
JsonNode presetNode;
for (auto const & entry : preset)
presetNode[entry.first] = entry.second;
handler.serializeRaw("preset", presetNode, {});
}
else
{
preset.clear();
JsonNode presetNode;
handler.serializeRaw("preset", presetNode, {});
for (auto const & entry : presetNode.Struct())
preset[entry.first] = entry.second;
}
}
2023-09-15 10:06:06 +02:00
void Rewardable::Configuration::serializeJson(JsonSerializeFormat & handler)
{
handler.serializeStruct("onSelect", onSelect);
handler.enterArray("info").serializeStruct(info);
handler.serializeEnum("selectMode", selectMode, std::vector<std::string>{SelectModeString.begin(), SelectModeString.end()});
handler.serializeEnum("visitMode", visitMode, std::vector<std::string>{VisitModeString.begin(), VisitModeString.end()});
handler.serializeStruct("resetParameters", resetParameters);
handler.serializeBool("canRefuse", canRefuse);
handler.serializeBool("showScoutedPreview", showScoutedPreview);
handler.serializeBool("coastVisitable", coastVisitable);
2023-09-15 10:06:06 +02:00
handler.serializeInt("infoWindowType", infoWindowType);
}
2023-04-30 15:13:07 +02:00
VCMI_LIB_NAMESPACE_END