|
From: Yoda-JM <yo...@us...> - 2010-01-12 23:59:49
|
Module: performous
Branch: master
Commit: 9099d9b334fcdf95ae2386c79fba9ac52bbb84ab
Author: Vincent Le Ligeour <yo...@us...>
Date: Wed Jan 13 00:59:05 2010 +0100
Added test to know if a song has a hiscore
---
game/database.cc | 5 +++++
game/database.hh | 1 +
game/hiscore.cc | 7 +++++++
game/hiscore.hh | 1 +
4 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/game/database.cc b/game/database.cc
index d04741c..ee68700 100644
--- a/game/database.cc
+++ b/game/database.cc
@@ -130,6 +130,11 @@ void Database::queryPerPlayerHiscore (std::ostream & os, std::string const& trac
}
}
+bool Database::hasHiscore(boost::shared_ptr<Song> s) const {
+ int songid = m_songs.lookup(s);
+ return m_hiscores.hasHiscore(songid);
+}
+
/*
int test(std::string const& name, std::string const& song, int score) {
Database d("database.xml");
diff --git a/game/database.hh b/game/database.hh
index c61ae47..259be37 100644
--- a/game/database.hh
+++ b/game/database.hh
@@ -101,6 +101,7 @@ class Database
void queryPerSongHiscore (std::ostream & os, boost::shared_ptr<Song> s, std::string const& track = "") const;
void queryPerPlayerHiscore (std::ostream & os, std::string const& track = "") const;
+ bool hasHiscore(boost::shared_ptr<Song> s) const;
bool noPlayers() const;
private:
diff --git a/game/hiscore.cc b/game/hiscore.cc
index 4c0bcae..4bd196d 100644
--- a/game/hiscore.cc
+++ b/game/hiscore.cc
@@ -71,6 +71,13 @@ Hiscore::HiscoreVector Hiscore::queryHiscore(int max, int playerid, int songid,
return hv;
}
+bool Hiscore::hasHiscore(int songid) const {
+ for (hiscore_t::const_iterator it = m_hiscore.begin(); it != m_hiscore.end(); ++it) {
+ if(songid == it->songid) return true;
+ }
+ return false;
+}
+
void Hiscore::load(xmlpp::NodeSet const& n) {
for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
diff --git a/game/hiscore.hh b/game/hiscore.hh
index 704fe61..7b02df3 100644
--- a/game/hiscore.hh
+++ b/game/hiscore.hh
@@ -72,6 +72,7 @@ class Hiscore
@param max limits the number of elements returned.
*/
HiscoreVector queryHiscore(int max = -1, int playerid = -1, int songid = -1, std::string const& track = "") const;
+ bool hasHiscore(int songid) const;
private:
typedef std::multiset<HiscoreItem>hiscore_t;
|