summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-01-20 15:45:40 +0100
committerandrew <xdotftw@gmail.com>2014-01-20 15:45:40 +0100
commitff2302ebd53453242175683587b19ae5de5d1aed (patch)
treea231b4f920f435800d5569e7649bd18533015896
parentScoreboard deserialization (diff)
downloadcuberite-ff2302ebd53453242175683587b19ae5de5d1aed.tar
cuberite-ff2302ebd53453242175683587b19ae5de5d1aed.tar.gz
cuberite-ff2302ebd53453242175683587b19ae5de5d1aed.tar.bz2
cuberite-ff2302ebd53453242175683587b19ae5de5d1aed.tar.lz
cuberite-ff2302ebd53453242175683587b19ae5de5d1aed.tar.xz
cuberite-ff2302ebd53453242175683587b19ae5de5d1aed.tar.zst
cuberite-ff2302ebd53453242175683587b19ae5de5d1aed.zip
-rw-r--r--src/Scoreboard.cpp11
-rw-r--r--src/Scoreboard.h18
-rw-r--r--src/WorldStorage/ScoreboardSerializer.cpp77
3 files changed, 92 insertions, 14 deletions
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 864837d3d..3ddf146a6 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -72,7 +72,10 @@ cObjective::eType cObjective::StringToType(const AString & a_Name)
-cObjective::cObjective(const AString & a_DisplayName, cObjective::eType a_Type) : m_DisplayName(a_DisplayName), m_Type(a_Type)
+cObjective::cObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type)
+ : m_DisplayName(a_DisplayName)
+ , m_Name(a_Name)
+ , m_Type(a_Type)
{}
@@ -90,7 +93,7 @@ void cObjective::Reset(void)
cObjective::Score cObjective::GetScore(const AString & a_Name) const
{
- ScoreMap::const_iterator it = m_Scores.find(a_Name);
+ cScoreMap::const_iterator it = m_Scores.find(a_Name);
if (it == m_Scores.end())
{
@@ -226,7 +229,7 @@ cScoreboard::cScoreboard()
cObjective* cScoreboard::RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type)
{
- cObjective Objective(a_DisplayName, a_Type);
+ cObjective Objective(a_Name, a_DisplayName, a_Type);
std::pair<cObjectiveMap::iterator, bool> Status = m_Objectives.insert(cNamedObjective(a_Name, Objective));
@@ -355,7 +358,7 @@ void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot)
-cObjective* cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot)
+cObjective * cScoreboard::GetObjectiveIn(eDisplaySlot a_Slot)
{
ASSERT(a_Slot < E_DISPLAY_SLOT_COUNT);
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index f7285a9cf..2ce614de7 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -54,10 +54,11 @@ public:
public:
- cObjective(const AString & a_DisplayName, eType a_Type);
+ cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type);
eType GetType(void) const { return m_Type; }
+ const AString & GetName(void) const { return m_Name; }
const AString & GetDisplayName(void) const { return m_DisplayName; }
/// Resets the objective
@@ -80,16 +81,19 @@ public:
private:
- typedef std::pair<AString, Score> TrackedPlayer;
+ typedef std::pair<AString, Score> cTrackedPlayer;
- typedef std::map<AString, Score> ScoreMap;
+ typedef std::map<AString, Score> cScoreMap;
- ScoreMap m_Scores;
+ cScoreMap m_Scores;
AString m_DisplayName;
+ AString m_Name;
eType m_Type;
+ friend class cScoreboardSerializer;
+
};
@@ -152,6 +156,8 @@ private:
cPlayerNameSet m_Players;
+ friend class cScoreboardSerializer;
+
};
@@ -198,7 +204,7 @@ public:
void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot);
- cObjective* GetObjectiveIn(eDisplaySlot a_Slot);
+ cObjective * GetObjectiveIn(eDisplaySlot a_Slot);
/// Execute callback for each objective with the specified type
void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
@@ -223,6 +229,8 @@ private:
cObjective* m_Display[E_DISPLAY_SLOT_COUNT];
+ friend class cScoreboardSerializer;
+
} ;
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index c2f13a092..bcac50bb6 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -109,21 +109,88 @@ bool cScoreboardSerializer::Save(void)
void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
{
a_Writer.BeginCompound("Data");
- a_Writer.BeginList("Objectives", TAG_Compound);
+ a_Writer.BeginList("Objectives", TAG_Compound);
+
+ for (cScoreboard::cObjectiveMap::const_iterator it = m_ScoreBoard->m_Objectives.begin(); it != m_ScoreBoard->m_Objectives.end(); ++it)
+ {
+ const cObjective & Objective = it->second;
- a_Writer.EndList();
+ a_Writer.BeginCompound("");
- a_Writer.BeginList("PlayerScores", TAG_Compound);
+ a_Writer.AddString("CriteriaName", cObjective::TypeToString(Objective.GetType()));
- a_Writer.EndList();
+ a_Writer.AddString("DisplayName", Objective.GetDisplayName());
+ a_Writer.AddString("Name", it->first);
- a_Writer.BeginList("Teams", TAG_Compound);
+ a_Writer.EndCompound();
+ }
+
+ a_Writer.EndList();
+
+ a_Writer.BeginList("PlayerScores", TAG_Compound);
+
+ for (cScoreboard::cObjectiveMap::const_iterator it = m_ScoreBoard->m_Objectives.begin(); it != m_ScoreBoard->m_Objectives.end(); ++it)
+ {
+ const cObjective & Objective = it->second;
+
+ for (cObjective::cScoreMap::const_iterator it2 = Objective.m_Scores.begin(); it2 != Objective.m_Scores.end(); ++it2)
+ {
+ a_Writer.BeginCompound("");
+
+ a_Writer.AddInt("Score", it2->second);
+
+ a_Writer.AddString("Name", it2->first);
+ a_Writer.AddString("Objective", it->first);
+
+ a_Writer.EndCompound();
+ }
+ }
+
+ a_Writer.EndList();
+
+ a_Writer.BeginList("Teams", TAG_Compound);
+
+ for (cScoreboard::cTeamMap::const_iterator it = m_ScoreBoard->m_Teams.begin(); it != m_ScoreBoard->m_Teams.end(); ++it)
+ {
+ const cTeam & Team = it->second;
+
+ a_Writer.BeginCompound("");
+
+ a_Writer.AddByte("AllowFriendlyFire", Team.AllowsFriendlyFire() ? 1 : 0);
+ a_Writer.AddByte("SeeFriendlyInvisibles", Team.CanSeeFriendlyInvisible() ? 1 : 0);
+
+ a_Writer.AddString("DisplayName", Team.GetDisplayName());
+ a_Writer.AddString("Name", it->first);
+
+ a_Writer.AddString("Prefix", Team.GetPrefix());
+ a_Writer.AddString("Suffix", Team.GetSuffix());
+
+ a_Writer.BeginList("Players", TAG_String);
+
+ for (cTeam::cPlayerNameSet::const_iterator it2 = Team.m_Players.begin(); it2 != Team.m_Players.end(); ++it2)
+ {
+ a_Writer.AddString("", *it2);
+ }
a_Writer.EndList();
+
+ a_Writer.EndCompound();
+ }
+
+ a_Writer.EndList();
a_Writer.EndCompound();
a_Writer.BeginCompound("DisplaySlots");
+ cObjective * Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_LIST);
+ a_Writer.AddString("slot_0", (Objective == NULL) ? "" : Objective->GetName());
+
+ Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_SIDEBAR);
+ a_Writer.AddString("slot_1", (Objective == NULL) ? "" : Objective->GetName());
+
+ Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME);
+ a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName());
+
a_Writer.EndCompound();
}