Remove one level of indent in statistics serialiser
This commit is contained in:
parent
de329dc5ad
commit
c6de5e9bc5
|
@ -13,10 +13,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace StatisticsSerializer
|
static auto MakeStatisticsDirectory(const std::string & WorldPath, std::string && FileName)
|
||||||
{
|
{
|
||||||
static auto MakeStatisticsDirectory(const std::string & WorldPath, std::string && FileName)
|
|
||||||
{
|
|
||||||
// Even though stats are shared between worlds, they are (usually) saved
|
// Even though stats are shared between worlds, they are (usually) saved
|
||||||
// inside the folder of the default world.
|
// inside the folder of the default world.
|
||||||
|
|
||||||
|
@ -27,14 +25,14 @@ namespace StatisticsSerializer
|
||||||
cFile::CreateFolder(Path);
|
cFile::CreateFolder(Path);
|
||||||
|
|
||||||
return Path + cFile::GetPathSeparator() + std::move(FileName) + ".json";
|
return Path + cFile::GetPathSeparator() + std::move(FileName) + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void SaveStatToJSON(const StatisticsManager & Manager, Json::Value & a_Out)
|
static void SaveStatToJSON(const StatisticsManager & Manager, Json::Value & a_Out)
|
||||||
{
|
{
|
||||||
if (Manager.Custom.empty())
|
if (Manager.Custom.empty())
|
||||||
{
|
{
|
||||||
// Avoid saving "custom": null to disk:
|
// Avoid saving "custom": null to disk:
|
||||||
|
@ -46,14 +44,14 @@ namespace StatisticsSerializer
|
||||||
{
|
{
|
||||||
Custom[NamespaceSerializer::From(Statistic).data()] = Value;
|
Custom[NamespaceSerializer::From(Statistic).data()] = Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void LoadCustomStatFromJSON(StatisticsManager & Manager, const Json::Value & a_In)
|
static void LoadCustomStatFromJSON(StatisticsManager & Manager, const Json::Value & a_In)
|
||||||
{
|
{
|
||||||
for (auto it = a_In.begin(); it != a_In.end(); ++it)
|
for (auto it = a_In.begin(); it != a_In.end(); ++it)
|
||||||
{
|
{
|
||||||
const auto & Key = it.key().asString();
|
const auto & Key = it.key().asString();
|
||||||
|
@ -78,31 +76,30 @@ namespace StatisticsSerializer
|
||||||
FLOGWARNING("Invalid statistic value for type \"{}\"", StatName);
|
FLOGWARNING("Invalid statistic value for type \"{}\"", StatName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Load(StatisticsManager & Manager, const std::string & WorldPath, std::string && FileName)
|
void StatisticsSerializer::Load(StatisticsManager & Manager, const std::string & WorldPath, std::string && FileName)
|
||||||
{
|
{
|
||||||
Json::Value Root;
|
Json::Value Root;
|
||||||
InputFileStream(MakeStatisticsDirectory(WorldPath, std::move(FileName))) >> Root;
|
InputFileStream(MakeStatisticsDirectory(WorldPath, std::move(FileName))) >> Root;
|
||||||
|
|
||||||
LoadCustomStatFromJSON(Manager, Root["stats"]["custom"]);
|
LoadCustomStatFromJSON(Manager, Root["stats"]["custom"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Save(const StatisticsManager & Manager, const std::string & WorldPath, std::string && FileName)
|
void StatisticsSerializer::Save(const StatisticsManager & Manager, const std::string & WorldPath, std::string && FileName)
|
||||||
{
|
{
|
||||||
Json::Value Root;
|
Json::Value Root;
|
||||||
|
|
||||||
SaveStatToJSON(Manager, Root["stats"]);
|
SaveStatToJSON(Manager, Root["stats"]);
|
||||||
Root["DataVersion"] = NamespaceSerializer::DataVersion();
|
Root["DataVersion"] = NamespaceSerializer::DataVersion();
|
||||||
|
|
||||||
OutputFileStream(MakeStatisticsDirectory(WorldPath, std::move(FileName))) << Root;
|
OutputFileStream(MakeStatisticsDirectory(WorldPath, std::move(FileName))) << Root;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue