Combined some file manager methods that had duplicated code into one getConfigFile method. Also fixed compile issues with the achievements stuff. (latter still WIP)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13615 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-09-01 21:11:15 +00:00
parent 046269cebb
commit e21ef8d40b
9 changed files with 49 additions and 48 deletions

View File

@ -1,5 +1,7 @@
# Generated by ./update_file_list.sh. Do not edit this file manually.
set(STK_SOURCES
src/achievements/achievement.cpp
src/achievements/achievements_manager.cpp
src/addons/addon.cpp
src/addons/addons_manager.cpp
src/addons/inetwork_http.cpp
@ -293,6 +295,8 @@ src/utils/translation.cpp
src/utils/vec3.cpp
)
set(STK_HEADERS
src/achievements/achievement.hpp
src/achievements/achievements_manager.hpp
src/addons/addon.hpp
src/addons/addons_manager.hpp
src/addons/dummy_network_http.hpp

View File

@ -21,6 +21,8 @@
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "io/xml_writer.hpp"
#include <sstream>
#include <stdlib.h>

View File

@ -23,7 +23,7 @@
#include <irrString.h>
#include <string>
#include "io/xml_writer.hpp"
#include "io/xml_node.hpp"
// ============================================================================
@ -34,7 +34,7 @@
*/
class Achievement
{
private:
protected:
uint32_t m_id;
bool m_achieved;
virtual void check() = 0;
@ -55,7 +55,7 @@ private:
public:
SingleAchievement (const XMLNode * input);
virtual ~SingleAchievement ();
virtual ~SingleAchievement () {};
}; // class Achievement
class MapAchievement : public Achievement
@ -67,7 +67,7 @@ private:
public:
MapAchievement (const XMLNode * input);
virtual ~MapAchievement ();
virtual ~MapAchievement () {};
}; // class Achievement
#endif

View File

@ -54,10 +54,20 @@ AchievementsManager::~AchievementsManager()
{
}
// ============================================================================
void AchievementsManager::parse()
{
}
// ============================================================================
void AchievementsManager::load()
{
}
// ============================================================================
void AchievementsManager::save()
{
std::string filename = file_manager->getConfigDir() + ("/challenges.xml");
std::string filename = file_manager->getConfigFile("challenges.xml");
std::ofstream achievements_file(filename.c_str(), std::ios::out);
@ -72,7 +82,7 @@ void AchievementsManager::save()
achievements_file << "<?xml version=\"1.0\"?>\n";
achievements_file << "<achievements>\n";
for (int i = 0; i < m_slots.size(); i++)
for (unsigned int i = 0; i < m_slots.size(); i++)
{
m_slots[i].save();
}
@ -81,9 +91,11 @@ void AchievementsManager::save()
achievements_file.close();
}
// ============================================================================
// ============================================================================
void AchievementsManager::AchievementsSlot::parse()
{
const std::string file_name = file_manager->getDataFile("items.xml");
const std::string file_name = file_manager->getDataFile("achievements.xml");
const XMLNode *root = file_manager->createXMLTree(file_name);
unsigned int num_nodes = root->getNumNodes();
for(unsigned int i = 0; i < num_nodes; i++)
@ -107,6 +119,19 @@ void AchievementsManager::AchievementsSlot::parse()
}
m_achievements[achievement->getID()] = achievement;
}
if(num_nodes != m_achievements.count())
if(num_nodes != m_achievements.size())
Log::error("AchievementsManager::parseAchievements","Multiple achievements with the same id!");
} // parseAchievements
// ============================================================================
void AchievementsManager::AchievementsSlot::load()
{
}
// ============================================================================
void AchievementsManager::AchievementsSlot::save()
{
}

View File

@ -25,6 +25,8 @@
#include <irrString.h>
#include <string>
#include <vector>
#include <map>
// ============================================================================
@ -39,7 +41,7 @@ private :
class AchievementsSlot
{
std::map<uint32_t, * Achievement> m_achievements;
std::map<uint32_t, Achievement *> m_achievements;
public :
void parse();
void load();

View File

@ -204,7 +204,7 @@ const ChallengeData* UnlockManager::getChallenge(const std::string& id)
*/
void UnlockManager::load()
{
const std::string filename=file_manager->getChallengeFile("challenges.xml");
const std::string filename=file_manager->getConfigFile("challenges.xml");
XMLNode* root = file_manager->createXMLTree(filename);
if(!root || root->getName() != "challenges")
{
@ -263,7 +263,7 @@ void UnlockManager::load()
void UnlockManager::save()
{
std::string filename = file_manager->getChallengeFile("challenges.xml");
std::string filename = file_manager->getConfigFile("challenges.xml");
std::ofstream challenge_file(filename.c_str(), std::ios::out);

View File

@ -844,7 +844,7 @@ std::string FileManager::checkAndCreateLinuxDir(const char *env_name,
void FileManager::redirectOutput()
{
//Enable logging of stdout and stderr to logfile
std::string logoutfile = getLogFile("stdout.log");
std::string logoutfile = getConfigFile("stdout.log");
Log::verbose("main", "Error messages and other text output will "
"be logged to %s.", logoutfile.c_str());
Log::openOutputFiles(logoutfile);
@ -874,16 +874,6 @@ std::string FileManager::getConfigDir() const
return m_config_dir;
} // getConfigDir
//-----------------------------------------------------------------------------
/** Returns the full path of a file in the user config directory which is
* used to store stdout/stderr if it is redirected.
* \param name Name of the file.
*/
std::string FileManager::getLogFile(const std::string& file_name) const
{
return getConfigDir()+"/"+file_name;
} // getLogFile
//-----------------------------------------------------------------------------
/** Returns the full path of a music file by searching all music search paths.
* It throws an exception if the file is not found.
@ -921,33 +911,14 @@ std::string FileManager::getFontFile(const std::string& file_name) const
} // getFontFile
//-----------------------------------------------------------------------------
/** Returns the full path of a highscore file (which is stored in the user
* specific config directory).
* \param file_name Name of the sound effect file.
*/
std::string FileManager::getHighscoreFile(const std::string& file_name) const
{
return getConfigDir()+"/"+file_name;
} // getHighscoreFile
//-----------------------------------------------------------------------------
/** Returns the full path of the challenge file (which is stored in a user
* specific config area).
/** Returns the full path of a file in the config dir
* \param file_name Name of the file.
*/
std::string FileManager::getChallengeFile(const std::string &file_name) const
std::string FileManager::getConfigFile(const std::string &file_name) const
{
return getConfigDir()+"/"+file_name;
} // getChallengeFile
//-----------------------------------------------------------------------------
/** Returns the full path of the tutorial file.
* \param file_name Name of the tutorial file to return.
*/
std::string FileManager::getTutorialFile(const std::string &file_name) const
{
return getConfigDir()+"/"+file_name;
} // getTutorialFile
//-----------------------------------------------------------------------------
/** Returns true if the given name is a directory.

View File

@ -106,10 +106,7 @@ public:
std::vector<std::string>getMusicDirs() const;
std::string getTextureFile (const std::string& fname) const;
std::string getDataFile (const std::string& fname) const;
std::string getHighscoreFile (const std::string& fname) const;
std::string getChallengeFile (const std::string& fname) const;
std::string getTutorialFile (const std::string& fname) const;
std::string getLogFile (const std::string& fname) const;
std::string getConfigFile (const std::string& fname) const;
std::string getItemFile (const std::string& fname) const;
std::string getGfxFile (const std::string& fname) const;
std::string getMusicFile (const std::string& fname) const;

View File

@ -59,7 +59,7 @@ void HighscoreManager::setFilename()
}
else
{
m_filename=file_manager->getHighscoreFile("highscore.xml");
m_filename=file_manager->getConfigFile("highscore.xml");
}
return;