|
From: Markus R. <god...@us...> - 2009-07-29 15:35:55
|
Module: performous
Branch: master
Commit: e33e68d97aa189fc1ce77955a5454c82bf679ab8
Author: Markus Raab <un...@ma...>
Date: Mon Jul 27 16:58:35 2009 +0200
Player Database now in xml
---
game/.gitignore | 2 +-
game/main.cc | 2 +-
game/players.cc | 28 +++++++++++++++++-----------
game/screen_players.cc | 2 +-
4 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/game/.gitignore b/game/.gitignore
index 13ba250..deb27f7 100644
--- a/game/.gitignore
+++ b/game/.gitignore
@@ -3,4 +3,4 @@ Makefile
highscore
highscore.txt
players
-players.txt
+players.xml
diff --git a/game/main.cc b/game/main.cc
index 70944de..4d80e8c 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -134,7 +134,7 @@ void mainLoop() {
Audio audio;
audioSetup(capture, audio);
Songs songs(songlist);
- Players players("players.txt"); // TODO: retrieve from configuration
+ Players players("players.xml"); // TODO: retrieve from configuration
ScreenManager sm;
Window window(config["graphic/window_width"].i(), config["graphic/window_height"].i(), config["graphic/fullscreen"].b(), config["graphic/fs_width"].i(), config["graphic/fs_height"].i());
sm.addScreen(new ScreenIntro("Intro", audio, capture));
diff --git a/game/players.cc b/game/players.cc
index 572d8f7..2ae321d 100644
--- a/game/players.cc
+++ b/game/players.cc
@@ -2,6 +2,7 @@
#include <fstream>
#include <boost/regex.hpp>
+#include <libxml++/libxml++.h>
Players::Players(std::string filename):
m_players(),
@@ -21,22 +22,29 @@ Players::~Players() {
}
void Players::load() {
- std::ifstream in (m_filename.c_str());
+ xmlpp::DomParser domParser(m_filename);
+ xmlpp::NodeSet n = domParser.get_document()->get_root_node()->find("/performous/players/player");
- std::string str;
- while (getline(in, str))
+ for (xmlpp::NodeSet::const_iterator it = n.begin(); it != n.end(); ++it)
{
- addPlayer(str);
+ xmlpp::Element& element = dynamic_cast<xmlpp::Element&>(**it);
+ xmlpp::Attribute* a = element.get_attribute("name");
+ addPlayer(a->get_value());
}
}
void Players::save() {
- std::ofstream out (m_filename.c_str());
+ xmlpp::Document doc;
+ xmlpp::Node* nodeRoot = doc.create_root_node("performous");
+ xmlpp::Element *players = nodeRoot->add_child("players");
for (players_t::const_iterator it = m_players.begin(); it!=m_players.end(); ++it)
{
- out << it->name << std::endl;
+ xmlpp::Element* player = players->add_child("player");
+ player->set_attribute("name", it->name);
}
+
+ doc.write_to_file_formatted(m_filename, "UTF-8");
}
void Players::update() {
@@ -91,16 +99,14 @@ void Players::filter_internal() {
int main(int argc, char** argv)
{
- if (argc != 2) return 1;
-
- std::string filter = argv[1];
- Players p("players.txt");
+ Players p("players.xml");
p.addPlayer("hubert");
- p.setFilter(filter);
for (size_t i=0; i<p.size(); i++)
{
std::cout << p[i].name << std::endl;
}
+
+ return 0;
}
*/
diff --git a/game/screen_players.cc b/game/screen_players.cc
index 4b58452..872c0bf 100644
--- a/game/screen_players.cc
+++ b/game/screen_players.cc
@@ -137,7 +137,7 @@ void ScreenPlayers::draw() {
// Format the song information text
if (m_search.text.empty()) {
oss_song << "No players found!";
- oss_order << "Check players.txt in current\n";
+ oss_order << "Check players.xml in current\n"; // TODO retrieve from configuration
oss_order << "directory for players";
} else {
oss_song << "Press enter to create player!";
|