summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/StatSerializer.cpp
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-05-11 19:30:54 +0200
committerandrew <xdotftw@gmail.com>2014-05-11 19:30:54 +0200
commite3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c (patch)
tree36e303c31006c346aaf895cdb631ff60dd9cdca6 /src/WorldStorage/StatSerializer.cpp
parentStatistic Manager (diff)
downloadcuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.tar
cuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.tar.gz
cuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.tar.bz2
cuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.tar.lz
cuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.tar.xz
cuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.tar.zst
cuberite-e3c6c8f3ddffdc368ebbc1a7688de2ca1b97167c.zip
Diffstat (limited to '')
-rw-r--r--src/WorldStorage/StatSerializer.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/WorldStorage/StatSerializer.cpp b/src/WorldStorage/StatSerializer.cpp
index 5c6724c60..66e5e1e9e 100644
--- a/src/WorldStorage/StatSerializer.cpp
+++ b/src/WorldStorage/StatSerializer.cpp
@@ -7,8 +7,6 @@
#include "../Statistics.h"
-#include <fstream>
-
@@ -19,7 +17,7 @@ cStatSerializer::cStatSerializer(const AString& a_WorldName, const AString& a_Pl
AString StatsPath;
Printf(StatsPath, "%s/stats", a_WorldName.c_str());
- m_Path = StatsPath + "/" + a_PlayerName + ".dat";
+ m_Path = StatsPath + "/" + a_PlayerName + ".json";
/* Ensure that the directory exists. */
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
@@ -88,6 +86,8 @@ void cStatSerializer::SaveStatToJSON(Json::Value & a_Out)
a_Out[StatName] = Value;
}
+
+ // TODO 2014-05-11 xdot: Save "progress"
}
}
@@ -107,11 +107,28 @@ bool cStatSerializer::LoadStatFromJSON(const Json::Value & a_In)
if (StatType == statInvalid)
{
- LOGWARNING("Invalid statistic type %s", StatName.c_str());
+ LOGWARNING("Invalid statistic type \"%s\"", StatName.c_str());
continue;
}
- m_Manager->SetValue(StatType, (*it).asInt());
+ Json::Value & Node = *it;
+
+ if (Node.isInt())
+ {
+ m_Manager->SetValue(StatType, Node.asInt());
+ }
+ else if (Node.isObject())
+ {
+ StatValue Value = Node.get("value", 0).asInt();
+
+ // TODO 2014-05-11 xdot: Load "progress"
+
+ m_Manager->SetValue(StatType, Value);
+ }
+ else
+ {
+ LOGWARNING("Invalid statistic value for type \"%s\"", StatName.c_str());
+ }
}
return true;