1
0

cWorld now saves/loads the scoreboard

This commit is contained in:
andrew 2014-01-22 15:49:21 +02:00
parent 9bd8f74b59
commit dd04f5a73c
4 changed files with 44 additions and 15 deletions

View File

@ -238,6 +238,8 @@ bool cTeam::HasPlayer(const AString & a_Name) const
void cTeam::Reset(void)
{
// TODO 2014-01-22 xdot: Inform online players
m_Players.clear();
}
@ -505,3 +507,4 @@ unsigned int cScoreboard::GetNumTeams(void) const

View File

@ -27,8 +27,6 @@ class cObjective
{
public:
// tolua_end
typedef int Score;
enum eType
@ -52,6 +50,8 @@ public:
E_TYPE_STAT_ENTITY_KILLED_BY
};
// tolua_end
static AString TypeToString(eType a_Type);
static eType StringToType(const AString & a_Name);
@ -60,6 +60,8 @@ public:
cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type, cWorld * a_World);
// tolua_begin
eType GetType(void) const { return m_Type; }
const AString & GetName(void) const { return m_Name; }
@ -85,6 +87,8 @@ public:
void SetDisplayName(const AString & a_Name);
// tolua_end
/// Send this objective to the specified client
void SendTo(cClientHandle & a_Client);
@ -135,6 +139,8 @@ public:
/// Removes all registered players
void Reset(void);
// tolua_begin
/// Returns the number of registered players
unsigned int GetNumPlayers(void) const;
@ -147,13 +153,15 @@ public:
const AString & GetPrefix(void) const { return m_Prefix; }
const AString & GetSuffix(void) const { return m_Suffix; }
void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; }
void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; }
void SetCanSeeFriendlyInvisible(bool a_Flag) { m_CanSeeFriendlyInvisible = a_Flag; }
void SetDisplayName(const AString & a_Name);
void SetPrefix(const AString & a_Prefix);
void SetSuffix(const AString & a_Suffix);
void SetPrefix(const AString & a_Prefix) { m_Prefix = a_Prefix; }
void SetSuffix(const AString & a_Suffix) { m_Suffix = a_Suffix; }
// tolua_end
private:
@ -183,8 +191,6 @@ class cScoreboard
{
public:
// tolua_end
enum eDisplaySlot
{
E_DISPLAY_SLOT_LIST = 0,
@ -194,11 +200,15 @@ public:
E_DISPLAY_SLOT_COUNT
};
// tolua_end
public:
cScoreboard(cWorld * a_World);
// tolua_begin
/// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision
cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type);
@ -228,13 +238,15 @@ public:
/// Execute callback for each objective with the specified type
void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
/// Send this scoreboard to the specified client
void SendTo(cClientHandle & a_Client);
unsigned int GetNumObjectives(void) const;
unsigned int GetNumTeams(void) const;
// tolua_end
/// Send this scoreboard to the specified client
void SendTo(cClientHandle & a_Client);
private:

View File

@ -12,6 +12,7 @@
#include "ChunkMap.h"
#include "Generating/ChunkDesc.h"
#include "OSSupport/Timer.h"
#include "WorldStorage/ScoreboardSerializer.h"
// Entities (except mobs):
#include "Entities/ExpOrb.h"
@ -248,6 +249,10 @@ cWorld::cWorld(const AString & a_WorldName) :
LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str());
cFile::CreateFolder(FILE_IO_PREFIX + m_WorldName);
// Load the scoreboard
cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard);
Serializer.Load();
}
@ -267,6 +272,10 @@ cWorld::~cWorld()
m_Storage.WaitForFinish();
// Unload the scoreboard
cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard);
Serializer.Save();
delete m_ChunkMap;
}

View File

@ -22,7 +22,12 @@
cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard)
: m_ScoreBoard(a_ScoreBoard)
{
Printf(m_Path, "%s/data/scoreboard.dat", a_WorldName.c_str());
AString DataPath;
Printf(DataPath, "%s/data", a_WorldName.c_str());
m_Path = DataPath + "/scoreboard.dat";
cFile::CreateFolder(FILE_IO_PREFIX + DataPath);
}
@ -33,7 +38,7 @@ bool cScoreboardSerializer::Load(void)
{
cFile File;
if (!File.Open(m_Path, cFile::fmReadWrite))
if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmReadWrite))
{
return false;
}
@ -60,7 +65,7 @@ bool cScoreboardSerializer::Load(void)
{
return false;
}
// Parse the NBT data:
cParsedNBT NBT(Uncompressed, strm.total_out);
if (!NBT.IsValid())
@ -81,7 +86,7 @@ bool cScoreboardSerializer::Save(void)
cFastNBTWriter Writer;
Writer.BeginCompound("");
m_ScoreBoard->RegisterObjective("test","test",cObjective::E_TYPE_DUMMY)->AddScore("dot", 2);
SaveScoreboardToNBT(Writer);
Writer.EndCompound();
@ -91,7 +96,7 @@ bool cScoreboardSerializer::Save(void)
cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size());
ASSERT(TestParse.IsValid());
#endif // _DEBUG
gzFile gz = gzopen((FILE_IO_PREFIX + m_Path).c_str(), "wb");
if (gz != NULL)
{