add new tutorial folder and a file containing the configuration

first tutorial configuration file 
Add to file_manager.cpp the method to check the tutorial file
tutorial data, to implement the XML loading

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7386 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
aeonphyxius 2011-01-13 00:27:03 +00:00
parent 2fed00594d
commit 840a77ed38
8 changed files with 61 additions and 63 deletions

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<challenge
id="basic_driving"
name="Basic Driving tutorial"
description="Come first in the At World's End Grand Prix with 3 Expert AI karts."
major="grandprix"
minor="timetrial"
track="canyon"
difficulty="easy"
karts="1"
num_players="1"
/>

View File

@ -623,6 +623,14 @@ std::string FileManager::getChallengeFile(const std::string &fname) const
return getConfigDir()+"/"+fname; return getConfigDir()+"/"+fname;
} // getChallengeFile } // getChallengeFile
//-----------------------------------------------------------------------------
/** Returns the full path of the tutorial file. */
std::string FileManager::getTutorialFile(const std::string &fname) const
{
return getConfigDir()+"/"+fname;
} // getTutorialFile
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Returns true if the given name is a directory. /** Returns true if the given name is a directory.
* \param path File name to test. * \param path File name to test.

View File

@ -98,6 +98,7 @@ public:
std::string getDataFile (const std::string& fname) const; std::string getDataFile (const std::string& fname) const;
std::string getHighscoreFile (const std::string& fname) const; std::string getHighscoreFile (const std::string& fname) const;
std::string getChallengeFile (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 getLogFile (const std::string& fname) const;
std::string getItemFile (const std::string& fname) const; std::string getItemFile (const std::string& fname) const;
std::string getMusicFile (const std::string& fname) const; std::string getMusicFile (const std::string& fname) const;

View File

@ -169,7 +169,6 @@ void TutorialScreen::eventCallback(GUIEngine::Widget* widget, const std::string&
// Launch tutorial // Launch tutorial
//m_tutorial_manager->getTutorial(selection)->setRace(); //m_tutorial_manager->getTutorial(selection)->setRace();
// FIXME this code have to be in Tutorial class (and loaded from file xD) // FIXME this code have to be in Tutorial class (and loaded from file xD)
RaceManager::MajorRaceModeType m_major; RaceManager::MajorRaceModeType m_major;
RaceManager::MinorRaceModeType m_minor; RaceManager::MinorRaceModeType m_minor;

View File

@ -46,6 +46,10 @@ TutorialData::TutorialData(const std::string& filename)
m_gp_id = ""; m_gp_id = "";
m_energy = -1; m_energy = -1;
std::string s_property;
int i_property;
float f_property;
XMLNode *root = new XMLNode( filename ); XMLNode *root = new XMLNode( filename );
// Check if the file have been load correctly // Check if the file have been load correctly
@ -56,12 +60,24 @@ TutorialData::TutorialData(const std::string& filename)
msg << "Couldn't load tutorial '" << filename << "': no tutorial node."; msg << "Couldn't load tutorial '" << filename << "': no tutorial node.";
throw std::runtime_error(msg.str()); throw std::runtime_error(msg.str());
} }
// Start the loading process (ordered as it is on the file)
std::string s_property; // ID
int i_property; if(!root->get("id", &s_property) )
float f_property; error("id");
setId(s_property);
// Mode // Name
if(!root->get("name", &s_property) )
error("name");
setName( _(s_property.c_str()) );
// Description
if(!root->get("s_property", &s_property) )
error("description");
setTutorialDescription( _(s_property.c_str()) );
// Major
root->get("major", &s_property); root->get("major", &s_property);
setMajor(s_property); setMajor(s_property);
@ -69,72 +85,27 @@ TutorialData::TutorialData(const std::string& filename)
root->get("minor", &s_property); root->get("minor", &s_property);
setMinor(s_property); setMinor(s_property);
// Name
if(!root->get("name", &s_property) )
error("name");
setName( _(s_property.c_str()) );
// ID
if(!root->get("id", &s_property) )
error("id");
setId(s_property);
// Description
if(!root->get("s_property", &s_property) )
error("description");
setTutorialDescription( _(s_property.c_str()) );
// Karts // Karts
if(!root->get("karts", &i_property) ) if(!root->get("karts", &i_property) )
error("karts"); error("karts");
setNumKarts(i_property); setNumKarts(i_property);
// Difficulty // Difficulty
root->get("difficulty", &s_property); root->get("difficulty", &s_property);
setDifficulty(s_property); setDifficulty(s_property);
// Time
root->get("time", &f_property); // one of time/position
setTime(f_property);
// Position
root->get("position", &m_position ); // must be set
if(m_time<0 && m_position<0)
error("position/time");
// Energy
root->get("energy", & i_property ); // This is optional
setEnergy(i_property);
// FIXME do we need position for the tutorials???????
// Position is optional except in GP and FTL
/*if(!root->get("position", &s_property))
error("position");
set
&&
//RaceManager::getWorld()->areKartsOrdered() ) // FIXME - order and optional are not the same thing
(m_minor==RaceManager::MINOR_MODE_FOLLOW_LEADER ||
m_major==RaceManager::MAJOR_MODE_GRAND_PRIX))
error("position");*/
if(m_major==RaceManager::MAJOR_MODE_SINGLE) if(m_major==RaceManager::MAJOR_MODE_SINGLE)
{ {
// Track // Track
if (!root->get("track", &s_property )) if (!root->get("track", &s_property ))
error("track"); error("track");
setTrack(s_property); setTrack(s_property);
if (!root->get("laps", &i_property))
error("laps");
setLaps(i_property);
}
else // GP
{
if (!root->get("gp", &m_gp_id )) error("gp");
if (grand_prix_manager->getGrandPrix(m_gp_id) == NULL) error("gp");
} }
// Num Players
root->get("num_players", &i_property);
setNumPlayers(i_property);
delete root; delete root;
} // TutorialData } // TutorialData
@ -152,7 +123,7 @@ void TutorialData::error(const char *id) const
} // error } // error
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Checks if this challenge is valid, i.e. contains a valid track or a valid /** Checks if this tutorial is valid, i.e. contains a valid track or a valid
* GP. If incorrect data are found, STK is aborted with an error message. * GP. If incorrect data are found, STK is aborted with an error message.
* (otherwise STK aborts when trying to do this challenge, which is worse). * (otherwise STK aborts when trying to do this challenge, which is worse).
*/ */
@ -334,3 +305,8 @@ void TutorialData::setEnergy(int energy)
{ {
m_energy = energy; m_energy = energy;
} }
void TutorialData::setNumPlayers (int num_players)
{
this->m_num_players = num_players;
}

View File

@ -43,6 +43,8 @@ private:
std::string m_track_name; std::string m_track_name;
int m_energy; int m_energy;
std::string m_filename; std::string m_filename;
int m_num_players;
// void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward); // void getUnlocks(const XMLNode *root, const std:: string type, REWARD_TYPE reward);
void error(const char *id) const; void error(const char *id) const;
@ -66,6 +68,7 @@ public:
void setMajor(std::string major); void setMajor(std::string major);
void setMinor(std::string minor); void setMinor(std::string minor);
void setNumKarts(int num_karts); void setNumKarts(int num_karts);
void setNumPlayers(int num_players);
virtual void check() const; virtual void check() const;
virtual bool raceFinished(); virtual bool raceFinished();

View File

@ -41,15 +41,14 @@ TutorialManager::TutorialManager()
// in main). // in main).
m_tutorial_manager = this; m_tutorial_manager = this;
// FIXME : Read tutorials from .../data
// ----------------------------- // -----------------------------
std::set<std::string> result; std::set<std::string> result;
file_manager->listFiles(result, "data/grandprix"); file_manager->listFiles(result, "data/tutorials");
for(std::set<std::string>::iterator i = result.begin(); for(std::set<std::string>::iterator i = result.begin();
i != result.end() ; i++) i != result.end() ; i++)
{ {
if (StringUtils::hasSuffix(*i, ".tutorial")) if (StringUtils::hasSuffix(*i, ".tutorial"))
addTutorial(file_manager->getDataFile("grandprix/"+*i)); addTutorial(file_manager->getDataFile("tutorials/"+*i));
} }
// Hard coded challenges can be added here. // Hard coded challenges can be added here.
@ -125,7 +124,7 @@ void TutorialManager::load()
{ {
std::cerr << "Tutorial file '" << filename << "' will be created." std::cerr << "Tutorial file '" << filename << "' will be created."
<< std::endl; << std::endl;
save(); //save();
if (root) delete root; if (root) delete root;
return; return;
@ -139,10 +138,11 @@ void TutorialManager::load()
delete root; delete root;
} // load } // load
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TutorialManager::save() //void TutorialManager::save()
{ //{
std::ofstream tutorial_file; // std::ofstream tutorial_file;
//std::string filename = file_manager->getChallengeFile("tutorial.xml"); //std::string filename = file_manager->getChallengeFile("tutorial.xml");
//challenge_file.open(filename.c_str()); //challenge_file.open(filename.c_str());
@ -163,6 +163,6 @@ void TutorialManager::save()
// //
//challenge_file << "</challenges>\n\n"; //challenge_file << "</challenges>\n\n";
//challenge_file.close(); //challenge_file.close();
} // save //} // save

View File

@ -48,7 +48,6 @@ public:
~TutorialManager (); ~TutorialManager ();
void addTutorial (Tutorial * m_tutorial); void addTutorial (Tutorial * m_tutorial);
void addTutorial (const std::string& filename); void addTutorial (const std::string& filename);
void save ();
vector <const Tutorial*> getTutorialsList(); vector <const Tutorial*> getTutorialsList();